Reputation: 103
How would I get this to include words that start with capital letters and lowercase? Because right now it is only lowercase.
$string = "you would love this @matt";
$pattern = '/(^|\W)(@([a-z]+))/';
$replacement = '$1<a href="/user/$3">$2</a>';
echo preg_replace($pattern, $replacement, $string);
Upvotes: -1
Views: 155
Reputation: 219804
Change [a-z]
to [a-zA-Z]
:
$pattern = '/(^|\W)(@([a-zA-Z]+))/';
Or use the i
modifier (it means make the match case insenstivive):
$pattern = '/(^|\W)(@([a-z]+))/i';
Upvotes: 2