PHP, I want to use regular expressions to get the array (@ Shaw, @ Tip, @ to S_3, @ in there) these four array elements, do not contain the @ space.
$str = ' @ Shaw @ S_3 @ the way @ there is @ ';
Preg_match_all ('/@+\s/', $str, $matchs);
Want xxx between @ and space (can be Chinese and English, underline and other symbols)
It's wrong of me to write like this. Ask the hero to help. Thanks, man.
Of course there are other ways to get the array (@ Shaw, @ Tip, @ To S_3 method, @ in there) also line, beg enlighten!
------Solution--------------------
$str = ' @ Shaw @ S_3 @ the way @ there is @ ';
Preg_match_all ("/@\s{1,}\s/", $str, $matchs);
\s (uppercase) denotes all non-whitespace characters followed by {1,} indicating that there must be at least one matching byte
------Solution--------------------
I was careless, and there was no need to \s the heel of a \s, to do so instead of the superfluous
------Solution--------------------
PHP code
[liangdong@bb-browser-test00.vm.baidu.com php_ project]$ php main.php Array ([0] = @ Shaw [1] = @ Tip [2] = @ S_3 method [3] = @ in there) [Liangdong@bb-brow Ser-test00.vm.baidu.com php_project]$ cat main.php!--? php$content = "@ zhong Xiao @ Sharp Trap @ S_3 method @ @"; $n _match = Preg_match_all ('/@.*/U ', $content, $matches), if ($n _match) {$res = Array_filter ($matches [0], function ($item) {return trim ($item, "@ ");}); Print_r ($res);}? -->