Continue to ask questions about regular expressions $ str & nbsp ;=& nbsp; "yesterday & nbsp ;@ & nbsp; hiaaaa & nbsp; dd @ Test & nbsp; "; $ reg & nbsp; = & nbsp; "/([^ @] + (? = \ S)/"; $ arr & nbsp ;=& nbsp; preg_split ($ reg, $ str,-1, PRE continue to ask about regular expressions
$ Str = "yesterday @ test hiaaaa dd @ Test reverse replay ";
$ Reg = "/([^ @] + (? = \ S ))/";
$ Arr = preg_split ($ reg, $ str,-1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
Print_r ($ arr );
The result is
Array ([0] => yesterday [1] => @ [2] => test [3] => hiaaaa [4] => dd @ [5] => test [6] => repeat)
The expected result is
Array ([0] => yesterday @ [1] => test [2] => hiaaaa dd @ [3] => test [4] => repeat)
How can I modify the regular expression?
====================
Actually, I want to use a regular expression like the @ function in Weibo to split the @ user. The rule is "@ start + name + space". Is there any other better implementation method?
If you use this
$ Str = "yesterday @ test hiaaaa dd @ test @ 2 ";
In this way, I @ a friend at the end, but there is no space. Can I use regular expressions to determine? Regular expressions are shared:
------ Solution --------------------
$ Str = "yesterday @ test hiaaaa dd @ test @ 2 ";
$ Reg = "/(@ \ S + )/";
$ Arr = preg_split ($ reg, $ str,-1, PREG_SPLIT_DELIM_CAPTURE
------ Solution --------------------
PREG_SPLIT_NO_EMPTY );
Print_r ($ arr );
Array
(
[0] => yesterday
[1] => @ test
[2] => hiaaaa dd
[3] => @ test
[4] => repeat
[5] => @ Friend 2
)