I am developing a PHP application which needs a regular expression to replace the @ mentions like twitter. Also the regular expression should satisfy the following needs.
As twitter can contain up to 15 characters, you could write it like this to avoid some bugs:
$tweet = preg_replace("/(^\w)@(\w{1,15})/i", "\\1@\\2", $tweet);