I’m producing HTML from twitter search results. Happily using the Net::Twitter module 🙂
One of the rules in Twitter is that all-numeric hashtags are not links.
This allows to unambiguously tweet things like “ur not my #1 anymore”, as in here: http://twitter.com/natarias2007/status/11246320622
The solution I came up with looks like:
$tweet =~ s{#([0-9]*[A-Za-z_]+[0-9]*)}{<a href="http://twitter.com/search?q=%23$1">#$1</a>}g;
It seems to work (let’s hope), but I’m still curious… how would you do it?
EDIT: that regex i came up earlier was not correct!
see below for a better answer 🙂
Your regexp wouldn’t capture anchors that contain more than one letter separated by numbers, e.g. #a0a:
e.g. consider
my $tweet = "hello #123 hello #abc1a hello #a0a";Your code produces
hello #123 hello <a href="http://twitter.com/search?q=%23abc1">#abc1</a>a hello <a href="http://twitter.com/search?q=%23a9">#a0</a>aand mine produces
hello #123 hello <a href="http://twitter.com/search?q=%23abc1a">#abc1a</a> hello <a href="http://twitter.com/search?q=%23a9a">#a0a</a>