Ask a regular: How to get more than one regular fragment in a string

Source: Internet
Author: User
Title

Example: There is a string ah real deal Safi @ Assad @ The unofficial Caesar's occurrence of the hair of the Fengfengguangguang sent scholar @abc

Match the fragment at the beginning of the @ with a space or a trailing end, hoping to get @ Assad at unofficial @ Fengfengguangguang @abc four results (should be in an array)

How do you write such a regular?


Reply to discussion (solution)

$s = ' ah real deal's Safi @ Assad at the occurrence of the unofficial Caesar's Fengfengguangguang sent by the scholar @abc ';p reg_match_all ('/@.+ (\s|$)/U ', $s, $m);p rint_r ($m [0]);

Thanks a lot....

is Preg_match_all () ..... I took Preg_match () for half a day

Why don't you read the manual?

PHP code?123$s= ' Ah Real deal's Safi @ Assad @ the occurrence of the unofficial Caesar's hair @ Fengfengguangguang sent scholar @abc ';p reg_match_all ('/@.+ (\s|$)/U ', $s, $m);p rint_r ($m [0]);

Is there a preg_replace_all () version of Preg_replace ()? Would you like to replace all these with links?

Preg_replace () could have been replaced many times, the function you said did not.

  • 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.