Skip to content

Instantly share code, notes, and snippets.

@rakauchuk
Created September 16, 2013 15:28
Show Gist options
  • Save rakauchuk/6582195 to your computer and use it in GitHub Desktop.
Save rakauchuk/6582195 to your computer and use it in GitHub Desktop.
Regex to conditionally replace Twitter hashtags with hyperlinks
<?
// (^|\s)#(\w*[a-zA-Z_]+\w*)
$str = preg_replace('/(^|\s)#(\w*[a-zA-Z_]+\w*)/', '\1#<a href="http://search.twitter.com/search?q=%23\2">\2</a>', $str);
// ...
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment