I assume this is some to do with regex, but it\'s an art all it\'s own - and I need some help.
When we display a story, we store all the text in a varilable - let\'s
$input = preg_replace('/(^|\s)@([a-z0-9_]+)/i',
'$1@$2',
$input);
See it
It matches a @
which is preceded by whitespace or nothing ( when it is at the beginning).
It can also be shorted using positive lookbehind as:
$input = preg_replace('/(?<=^|\s)@([a-z0-9_]+)/i',
'@$1',
$input);
Which matches only the twitter name but only if there is space or nothing before that.