Possible duplicate:
How to link text using ActionScript 3
I use a regex to search for links in a common line and highlight this text (underline, href, whatever).
Here is what I still have:
var linkRegEx:RegExp = new RegExp("(https?://)?(www\\.)?([a-zA-Z0-9_%]*)\\b\\.[a-z]{2,4}(\\.[a-z]{2})?((/[a-zA-Z0-9_%]*)+)?(\\.[a-z]*)?(:\\d{1,5})?","g");
var link:String = 'generic links: www.google.com http://www.yahoo.com stackoverflow.com';
link = addLinks(linkRegEx,link);
textField.htmlText = link;
function addLinks(pattern:RegExp,text:String):String{
while((pattern.test(text))!=false){
text=text.replace(pattern, "<u>link</u>");
}
return text;
}
I get all the text replaced by the link. I would like to have the same text that matches the expression instead of "link". I tried
text=text.replace(pattern, "<u>"+linkRegEx.exec(text)[0]+"</u>");
but I ran into a problem. I donβt think I fully understand how the regex and replacement method work.
source
share