Need to find the <img src tags

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

Moderator: General Moderators

Post Reply
Rauken
Forum Newbie
Posts: 1
Joined: Mon Dec 19, 2005 4:10 am

Need to find the <img src tags

Post by Rauken »

I need help with constructing a regular expression that finds the src of image tags. I use .net.

I have all the html in a string and what I need to match is this:
<img src="xxxx">

Some of the image tags can look like this:
<img class="s" src="xxxx">

or:
<img xmlns:i18n="http://apache.org/cocoon/i18n/2.1" src="xxx">

Any regexp gurus out there?

/Magnus
User avatar
Skittlewidth
Forum Contributor
Posts: 389
Joined: Wed Nov 06, 2002 9:18 am
Location: Kent, UK

Post by Skittlewidth »

This post might help you get started:

viewtopic.php?p=79152&highlight=#79152


Redmonkey gives a good regex halfway down that won't catch the src of <script> tags unlike my final soluction (I knew there wouldn't be scripts on the page I was running it on.)


You will possibly need to adapt this a bit for xml though.
User avatar
sweatje
Forum Contributor
Posts: 277
Joined: Wed Jun 29, 2005 10:04 pm
Location: Iowa, USA

Post by sweatje »

in general, something like:
/<img\b[^>]*src="([^"]+)"[^>]*>/

it becomes more complicated if you want to support src="something" or src='something' though.
Post Reply