I found this : "Need help parsing tweet text?", on dev.twitter.com
Take a look on the Twitter text processing library we’re using for auto linking and extraction of usernames, lists & hashtags.
(there's ruby, java and javascript librairies)
They are quite enormous, as twitter must take into account every possible case.