I want to creat a reg exp for it

Hi
Suppose that I have saved the content of an HTML file in a variable, named strContent. I want to find all locations in this HTML matching this pattern:

<img src="......................" ....>
Where src DOES NOT start with "http://", and change them to such:
<img src="http://domain.com/folder/............................" ....>
That is, I want to add http://domain.com/folder/ to the begining of the SRC attributes which have missed it.

How would you design a regexp for it?
Huji
LVL 14
hujiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ThaSmartUnoCommented:
"/(?:[sS][rR][cC]\s*=)(?:[\s""']*)(.*?)(?:[\s>""'])/im"

i used this in a php page, and it returns ALL the src attributes ... including all the ones with the http:// ... so you may need to change this around ... it also returns javascript src's
0
hujiAuthor Commented:
Well I coded what I needed in PHP, very simply. We should accept that PHP uses RegExp in a better way when compared with ASP (VBscript indeed.)
Also, I've designed a regexp that finds the "src"s in ASP. But the problem is with the replacing part. In PHP you can simply choose the second sub-pattern to be changed, but you can't do the same in ASP.... I've coded some ways, but it is not neat and tidy, AT ALL. That's why I asked it here.



EVERYBODY, please provide me with the full code, that replaces the needed parts in the string.

Thanks
huji
0
fozyletCommented:
this does the find/replace thing well... but does not exclude the ones with http... some tuning needed on regex

<%
Option Explicit

Dim str
str = "<img src=""logo.gif"" >sfgjh<img src=""banner.gif"" >"

Dim objRegExp
Set objRegExp = New RegExp

objRegExp.IgnoreCase = True
objRegExp.Global = True

'Repalce all instances of Perl with ASP
objRegExp.Pattern = "(<img src=)(( *|\"")?)([^http:\/\/])([^\""]*)(( *|\"")?)( *)>"
str = objRegExp.Replace(str, "<img src=""http://gcek.net/img/$5"">")
response.write str

Set objRegExp = Nothing        'Clean up!

%>
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

fozyletCommented:
This one is better... http is aught now... :)

<%
Option Explicit

Dim str
str = "<img src=""http://photos1.blogger.com/img/163/3635/320/IMG_2675.jpg"" >sfgjh src=fdg <java src=some.js> <a href=http://gcek.net><img src=""banner.jpg"" ></a>"

Dim objRegExp
Set objRegExp = New RegExp

objRegExp.IgnoreCase = True
objRegExp.Global = True

'Repalce all instances of Perl with ASP
objRegExp.Pattern = "(<img src=)(( *|\"")?)(?!http:)([^\""]*)(( *|\"")?)( *)>"
str = objRegExp.Replace(str, "<img src=""http://gcek.net/img/$4"">")
response.write str

Set objRegExp = Nothing        'Clean up!

%>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hujiAuthor Commented:
Well, I still need some RegExp references! I feel there are things for me to learn! the $4 was the key, but I hadn't seen it before! :o(      (Would be glad if you recommend me a good online resource)

Now some questions:
1) About the pattern you made:
"(<img src=)(( *|\"")?)(?!http:)([^\""]*)(( *|\"")?)( *)>"
-----------------^
What is the marked part supposed to do? To match things like :       src= something.jpg         ??? (I'm specially focusing on the SPACE before the astrisk.
2) What if one IMG tag is like this:
<img alt="" src="a.jpg">
This pattern will miss that. I'm going to add a part like [^>]* after the (<img       in your pattern. Can you help me with it?
Thanks a lot
Huji
0
fozyletCommented:
i was looking at this page while doing that...
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/scriptinga.asp

well... microsoft's version of regexp is always a bit confusing! :)
0
hujiAuthor Commented:
fozylet,
I fixed it myself. Thank you for sharing your knowledge.
Good luck
Huji
0
fozyletCommented:
Thanks Huji :)
Any time!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.