Home >Backend Development >PHP Tutorial > 继续求教正则表达式有关问题

继续求教正则表达式有关问题

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-13 12:45:02922browse

继续求教正则表达式问题

<br />
$str = "昨天 @测试 hiaaaa dd@测试 反反复复";<br />
$reg = "/([^@]+(?=\s))/";<br />
$arr = preg_split($reg,$str,-1,PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );<br />
print_r($arr);<br />


结果是
Array ( [0] => 昨天 [1] => @ [2] => 测试 [3] => hiaaaa [4] => dd@ [5] => 测试 [6] => 反反复复 ) 


想要的结果是

Array ( [0] => 昨天 @ [1] => 测试 [2] => hiaaaa dd@ [3] => 测试 [4] => 反反复复 ) 


求教该如何修改正则?

==============
其实就是想把类似于微博里边@功能用正则来拆出@的人,规则是"@开头+人名+空格"不如此的话 有没有其他更好的实现方法?

如果用这个 类似于
$str = "昨天 @测试 hiaaaa dd@测试 反反复复@好友2";

这样在末尾@了好友,但是没有空格能否用正则判断?

正则表达式
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn