My favourite solution to this is to reuse or reimplement an existing good library for it: the best one I've found is AutoHyperlinks, which is used by the Macintosh IM client Adium - it is clever enough that if you put something like "bit.ly" or "fox.es" or "sn.im" in, it'll detect it as a hyperlink by checking against a list of valid TLDs.

http://code.google.com/p/maccode/wiki/AutoHyperlinks

Take a gander: it has lots of interesting edge cases, AND it has unit tests. This is definitely something worth nicking: I'm almost tempted to set up a web service that lets people chuck in text with URLs and get back HTML using AutoHyperlinks.