2014-02-26 216 views
0

我该如何获得包含以大写字母和小写字母开头的单词?因为现在它只是小写。Preg Replace中的小写字母和大写字母

感谢堆

$string = "you would love this @matt"; 
$pattern = '/(^|\W)(@([a-z]+))/'; 
$replacement = '$1<a href="/user/$3">$2</a>'; 
echo preg_replace($pattern, $replacement, $string); 

回答

2

变化[a-z][a-zA-Z]

$pattern = '/(^|\W)(@([a-zA-Z]+))/'; 

或者使用i修饰符(它意味着使比赛情况insenstivive):

$pattern = '/(^|\W)(@([a-z]+))/i'; 
相关问题