views:

85

answers:

2

I'm retrieving an unformatted String from a twitter feed. I want to be able to turn a text URL (http://blah.com/qwerty/) into a link but don't know how...is there a handy regular expression for this?

A: 

I haven't done this before, but the docs specify a TextEvent called Link, which will detect when you click on a HTML hyperlink that is inside a TextField - as long as the TextField has had HTML enabled. Details on how to make a TextField HTML-enabled will be in the docs too, but the specific information about using TextEvent.Link is here

Hope that helps.

debu

debu
Hi thanks but the problem is around actually making the text into HTML format. At the moment its just plain text, i need to find out a way to find out if the text is a link or not; then i can use the TextEvent...
daidai
+1  A: 
var protocol:String = "((?:http://|https://|ftp://|www\.))";
var urlPart:String = "([a-z0-9\-.#&?%$/=*_]+)";
var urlPattern:RegExp = new RegExp(protocol + urlPart , "ig");

//TEXT.match(urlPattern).length>0
TEXT = TEXT.replace(urlPattern, "<a href='$1$2'><u>$1$2</u></a>");
TEXT = TEXT.split("<a href='www.").join("<a target='_blank' href='http://www.") 

This should work. Make sure the textfield is selectable.

Guillaume Malartre
thanks Guillaume that looks perfect
daidai