Page 1 of 1

Match a string and then expand out around it

Posted: Sat Sep 06, 2008 7:11 am
by spib
Hi,

This is a bit of a tricky one - I need to find a url in some html by a given unique ID and then expand out the result to grab the full url.

So, example html

Code: Select all

<a href="/index.cfm?fuseaction=vids.individual&VideoID=695236" class="videoPicture" title="Click here to view: Video"><img src="http://b8.ac-images.myspacecdn.com/00676/88/69/676559688_thumb1.jpg" height="90" width="120" alt="695236" /></a>
I need to grab the http://b8.ac-images.myspacecdn.com/0067 ... thumb1.jpg url

So far I have

Code: Select all

/src=".*6559688(\.*)/i
But this doesn't match the whole url.

Can anyone help?

James

Re: Match a string and then expand out around it

Posted: Sat Sep 06, 2008 7:27 am
by GeertDD
Sometimes it is better to split things up over multiple steps. I think in your case it would may help as well.

First select all URLs using a generic regex. Then loop over all the matches and check for a certain ID.

Re: Match a string and then expand out around it

Posted: Sat Sep 06, 2008 7:44 am
by spib
Great suggestion, that worked a treat