HighDots Forums  

retrieving <a> tags of a string with RegExp

JavaScript discussion (multi-lingual) JavaScript discussion (alt.comp.lang.javascript)


Discuss retrieving <a> tags of a string with RegExp in the JavaScript discussion (multi-lingual) forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Fred
 
Posts: n/a

Default retrieving <a> tags of a string with RegExp - 09-14-2006 , 04:16 AM






Hi,

I would like to get an array of <a> html tags og a string.

I have done this but it doesnt works :

var reg;
var str='Bonjour, ceci est un test, une <a
href="phrase.php">phrase</a> décrivant un <img src="mot.gif" alt="mot">
assez <a href="important.php">important</a>';

reg=new RegExp('<a [^<|>]+>([^<|>]*)<\/a>', "gi");

matchstr=reg.exec(str);
if (matchstr == null)
alert("No match");
else
{
alert(matchstr.length);
for (var i = 0; i < matchstr.length; i++)
{
alert(matchstr[i]);
}

}


My BUG :
matchstr only contains <a href="phrase.php">phrase</a> bu not <a
href="important.php">important</a> !!


How to do then ?

Thanks for any help on it !

Regards

Fred

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.