Match a string and then expand out around it

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
spib
Forum Newbie
Posts: 9
Joined: Wed Jul 09, 2003 2:09 am

Match a string and then expand out around it

Post 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
User avatar
GeertDD
Forum Contributor
Posts: 274
Joined: Sun Oct 22, 2006 1:47 am
Location: Belgium

Re: Match a string and then expand out around it

Post 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.
spib
Forum Newbie
Posts: 9
Joined: Wed Jul 09, 2003 2:09 am

Re: Match a string and then expand out around it

Post by spib »

Great suggestion, that worked a treat
Post Reply