Hello,
I am using a regular expression to find links in a generic string and highlight that text(underline, a href, anything).
Here's what I have so far:
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;//textField is a TextField I have on stage
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 with "link". I'd like to have the same text that was matching the expresion instead of "link". I tried
text=text.replace(pattern, "<u>"+linkRegEx.exec(text)[0]+"</u>");
but I ran into trouble. I don't think I fully understand how regex and the replace method work.