Regex to do some replacing

If I have the following in some HTML
<IMG alt="" hspace=0 src="cid:00c801c4a19b$847576f0$6500a8Garyc0" align=baseline border=0>

I need to get this bit i.e. the src of the image
cid:00c801c4a19b$847576f0$6500a8Garyc0

and replace it with for example this
displayimage.asp

I'm not sure if the src will always be enclosed by " "  but I can't find any that aren't, and this only applies to the img tag but obviously src could be in other tags so it needs to check that it is an img tag.
LVL 58
GaryAsked:
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.

poopallCommented:
0
GaryAuthor Commented:
Read the question I asked
0
kingsfan76Commented:
gary, here's something i tested that might work, but it does based on the presumption that the string inside the "src=" is surrounded by double quotes:

<%
dim regExpTest, testString
set regExpTest = new regexp
regExpTest.Pattern = "src=\x22\S+\x22"
regExpTest.IgnoreCase = true
regExpTest.Global = true

testString = "<IMG alt="""" hspace=0 src=""cid:00c801c4a19b$847576f0$6500a8Garyc0"" align=baseline border=0>"
testString = testString & "<input name=""ok""><IMG src=""fdsgsg345345346534534fs"">"

testString = regExpTest.Replace(testString, "src=""whatever.jpg""")

Response.Write(testString)

Response.End
%>

basically this is the reg expression i used:

src=\x22\S+\x22

where "\x22" represent a double quote
"\S" = all non-white space character, so i also assume there is no space in the src string.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

kingsfan76Commented:
>>it needs to check that it is an img tag.

hm didn't pay attention to that the first time.
gonna need to modify the reg expression

0
HilaireCommented:
This should do the trick

Function ReplaceImgSrc(strIn, strNewSrc)
dim objRX
set objRX = new RegExp
with objRX
      .pattern = "<IMG ([^>]*)?src=\x22?([^ >]*)\x22?([^>]*)?>"
      .ignorecase = true
      .global = true
      ReplaceImgSrc = .replace(strIn, "<IMG $1src=""" + strNewSrc + """$3>")
end with
set objRX = nothing
end Function

'test code
dim str
str = "line 1<IMG alt="""" hspace=0 src=""cid:00c801c4a19b$847576f0$6500a8Garyc0"" align=baseline border=0><BR>line2"
msgbox ReplaceImgSrc(str, "new.jpg")

HTH

Hilaire
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
GaryAuthor Commented:
Seems to work grand for me Hilaire
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.