PHP, little brother I want to use the regular expression to get the array (@ Shaw, @ Tip, @ To S_3 method, @ in there) these four array elements, do not contain the @ space

Source: Internet
Author: User
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);}? --> 
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.