I work with a WCMS and what I am attempting to do is extract the image source from a HTML hyperlink/image.
In a nutshell, I have created an array which takes a text object (the WCMS calls this a WEM tag). I want to preload the image embedded within that text object as the thing I am creating is an image rotator. It looks something like this...
Expand|Select|Wrap|Line Numbers
- if (document.images) {
- img1 = new Image();
- //...
- img1.src = <WEM TEXT0005></WEM>;
- //...
- }
- var tileArray = new Array();
- tileArray[0] = <WEM TEXT0005></WEM>
- //...
What I need returned is something like...
"advert-tile-1.jpg"
At the moment I have...
Expand|Select|Wrap|Line Numbers
- <script language="JavaScript">
- reg = /src=\".+\.jpg\"/;
- string = new String ('<a href="blah.htm" title="Blah"><img src="advert-tile-1.jpg" width="175" height="180" alt="" border="0" /></a>');
- var matches = string.match(reg);
- document.write(matches);
- </script>
src="advert-tile-1.jpg"
So I just need to get rid of the 'src='.
In any other language you could use a Positive Lookbehind (?<=text) on the 'src=' but seeing as JavaScript does not support this, I'm a little stumped!
Any help would be greatly appreciated.
Thank you.