在php中,如果我捕获一个字符串
$string = 'gardens, countryside @teddy135'
如何将@username从该字符串捕获到php用户名中的一个新变量,以@开头并在空格或字符串结尾处终止?
所以我最终会
$string = 'gardens, countryside' $username ='@teddy135'
发布于 2015-12-18 06:22:25
使用下列正则表达式
\s@(\w+)\b\s:匹配一个空间@:匹配@字面意思(\w+):匹配一个或多个字母数字字符(包括_ ),并将其放在第一个捕获组中\b:字界代码:
$re = "/\\s@(\\w+)\\b/";
$str = "gardens, countryside @teddy135 @tushar and @abc";
preg_match_all($re, $str, $matches);发布于 2015-12-18 06:33:28
$regex = "/\s(@\S+)/";
$mystr = "gardens, countryside @teddy135 @xyz-12 and @abc.abc";
preg_match_all($regex, $mystr, $matches);
print_r($matches);https://stackoverflow.com/questions/34349567
复制相似问题