PHP Twitterify function regex doesn't exclude starting numbers <p>I'm using the code</p> <pre><code>function twitterify($ret) { $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t&lt; ]*)#", "\\1&lt;a href=\"\\2\" target=\"_blank\"&gt;\\2&lt;/a&gt;", $ret); $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r&lt; ]*)#", "\\1&lt;a href=\"http://\\2\" target=\"_blank\"&gt;\\2&lt;/a&gt;", $ret); $ret = preg_replace("/@(\w+)/", "&lt;a href=\"http://www.twitter.com/\\1\" target=\"_blank\"&gt;@\\1&lt;/a&gt;", $ret); $ret = preg_replace("/#(\w+)/", "&lt;a href=\"http://twitter.com/search?q=\\1\" target=\"_blank\"&gt;#\\1&lt;/a&gt;", $ret); return $ret; } </code></pre> <p>to parse text from Tweets and add links. If #1 appears in the Tweet text then a hashtag link will be created for it. That's incorrect since hashtags can't start with numbers.</p> <p>How can the regular expressions be modified to correct this?</p> <p>Also special characters should be excluded according to <a href="http://www.hashtags.org/platforms/twitter/what-characters-can-a-hashtag-include/" rel="nofollow">this</a>.</p>