Page 1 of 1

Need to find the <img src tags

Posted: Mon Dec 19, 2005 4:18 am
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

Posted: Mon Dec 19, 2005 4:32 am
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.

Posted: Mon Dec 19, 2005 8:40 am
by sweatje
in general, something like:
/<img\b[^>]*src="([^"]+)"[^>]*>/

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