Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Regular Expressions

Status
Not open for further replies.

FateFirst

Programmer
Apr 15, 2002
212
GB
Hi.

I am doing some stuff in asp/vbscript and I am currently having a few issues.

I have a variable which contains a load of data (sample data below). What I am looking to do is use reg. exp. to find particular items and if found then extract this particular information and loop through and basically 'response.write' the results.

Data sample:
Code:
strData = "<P class=MsoNormal 0cm 0pt><FONT face=Arial><FONT size=2><SPAN 12pt; FONT-FAMILY: Arial; mso-fareast-font-family: ?Times New Roman?; mso-ansi-language: EN-GB; mso-fareast-language: EN-US; mso-bidi-language: AR-SA mso-bidi-font-family: 13.0pt; mso-bidi-font-size: Light?; MT Sans ?Gill><IMG alt="" hspace=0 src="H:\Projects\temp\dir1\29-11-04\website\image1.gif" align=baseline border=0>&nbsp; <IMG alt="" hspace=0 src="H:\Projects\temp\dir1\29-11-04\website\image2.gif" align=baseline border=0></SPAN></FONT></FONT></P>"

The elements I am looking to FIND is whether an '<IMG' tag is contained within it and is so then pull out the path to the file. So running it on the above data would result in the following data being posted to back to the webpage:

Code:
H:\Projects\temp\dir1\29-11-04\website\image1.gif
H:\Projects\temp\dir1\29-11-04\website\image2.gif

Just not sure how to do it really. I have read a few tutorials but....to be honest...im still lost. Anyone able to point me in the right direction or give me something to start with? ;)

Thanks a lot peeps!

- FateFirst
 
Heres a quick sample of what ive been playing with:

Code:
set re = new RegExp
re.ignorecase = true
re.global = true
re.pattern = "src="".*"""
set matches = re.execute(strData)
re.pattern = "src=""""|<[^>]+>"
For each match in matches
	strMatch = trim(re.Replace(match.value, ""))
	response.write("<b>" & strMatch & "</b><br>")
Next

- FateFirst
 
A starting point:
tmpArr = Split(strData, "<")
For i = 0 To UBound(tmpArr)
If Left(UCase(tmpArr(i)), 4) = "IMG " Then
s = InStr(1, tmpArr(i), "src=", 1) + 5
q = Mid(tmpArr(i), s - 1, 1)
Response.Write Mid(tmpArr(i), s, InStr(s, tmpArr(i), q, 1) - s) & "<BR>"
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top