The FindURL class (v1.0)
Please note: This class has been updated. Please click here to see the latest changes.
Whilst I was playing around with the Twitter API I was beginning to get wound up by the fact that the XML feed from Twitter only sends out text versions of tweets and not HTML versions. For example, lets say a tweet says “Check out this cool link: http://www.plagro.com”, the xml feed from twitter would send out:
Check out this cool link: http://www.plagro.com"
as oppose to the html version containing the “a” link tag:
Check out this cool link: <a href="http://www.plagro.com">http://www.plagro.com</a>
So after trawling the forums looking for alternative feeds and/or HTML convertors, I came to the conclusion that it would be easier to write a small class that simply finds links within blocks of text and adds in the html tags so it can be displayed as HTML text. The result is the FindURL class.
You can find the FindURL class here and example files here.
Using the FindURL class is very simple. Firstly unzip it into the place where you store all of your actionscript classes and then use the following two lines of AS code whenever it’s needed. Feed it the text you want converting and then receive the String it returns.
//create a new FindURL and send it the text to process
var linkFinder:FindURL = new FindURL(testString);
//return the new processed text
var newString:String = linkFinder.Process();
Finally, please note that I found the Regular Expression used in my FindURL class online. It IS borrowed, it may not be perfect and I can’t offer you any support on it. I will also happily credit the line’s author when I eventually work out who that is – but that particular piece of code has been used seemingly dozens of times by different developers so the author is still ambiguous.
Hope it’s of use to you! Let me know how you get on and if there’s any way you’d like to see it expanded – I’m always open to suggestion.

sandra407 says:
September 9th, 2009 at 4:33 pm
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
The Hippy says:
September 9th, 2009 at 7:45 pm
Thanks Sandra, glad it’s of use to you! If you have any ideas for any future experiments/classes I’m open to suggestions. Otherwise you can get updates by following my Twitter feed @burnedouthippy. Thanks again
ben says:
September 7th, 2010 at 1:43 pm
hi, thank you for this class, it is amazing. is it possible to open url’s in a new tab/window.
i don’t know where to place the _blank.
thank you in advance.
bf says:
September 7th, 2010 at 2:07 pm
why are u deleting questions?
The Hippy says:
September 30th, 2010 at 2:21 pm
Hey bf (I’m presuming you’re also Ben?), I never delete questions or comments unless they are spam…but occasionally I don’t check in on my blog and questions get missed from the approval process.
In answer to the Ben question, try using my getURL() class
mars says:
September 30th, 2010 at 2:50 pm
Hey, just what i needed! thanks! great class. works great! Just one question, is it possible to make the links open in a blank window instead of itself?
Oh, im not the only one with this question. Hope to hear from u soon.
thanks,
Mars
mars says:
September 30th, 2010 at 2:51 pm
Hey, just what i needed! thanks! great class. works great! Just one question, is it possible to make the links open in a blnk window instead of itself?
Oh, im not the only one with this question. Hope to hear from u soon.
thanks,
Mars
mars says:
September 30th, 2010 at 2:53 pm
see u just answered my/our question. Thanks! you’re the bomb!
mars says:
September 30th, 2010 at 3:34 pm
Hey Hippy,
You are saying i should use your getURL() class to get the links to open in a new window. I have no clue how to combine them.
Could you help me out?
thanks,
Mars
The Hippy says:
October 4th, 2010 at 10:49 am
Ok dude, forget everything I said about getURL – I simply didn’t have a chance to look at my class properly (I go through very busy periods). Basically all FindURL is doing is returning a HTML tagged version of a string. So it looks for what could be a link in a text string and then adds HTML a tags.
So to make it open in a new browser you need to find the href part of the regex statement and add a target _blank. Open the FindURL class in an editor and look for:
href=’$2′
replace it with:
href=’$2′ target=’_blank’
and that should work the way you want it to. If I get around to it I’ll add a setting to the FindURL class so you can choose your target from the outset…but until then this should be a quick fix. Hope that helps!!
mars says:
October 4th, 2010 at 10:58 am
Yes Thanks, I was just working on it, and i found that solution too!
I was just posting you this message when i got ur answer in.
I replaced line 27 of ur findURL class with this;
_wholeThing = textToProcess.replace(regExp1 , ‘ $2‘);
it works perfectly!
Thanks for ur support!
Hippy, your the best!
mars says:
October 4th, 2010 at 11:03 am
thats not what i replaced it with! i guess one of the website’s scripts kinda ripped what i originally posted.
The Hippy says:
October 4th, 2010 at 12:06 pm
I’ve replaced the class with a new version – http://www.burnedouthippy.com/2010/10/the-findurl-class-v1-2/ – this should make things easier for you in the future.
Cheers for the continued interest.
mars says:
October 4th, 2010 at 2:06 pm
awesome!