Beginners ask a regular question

Source: Internet
Author: User
The research long time didn't get it right.

Will
/aaa/bbb/ccc

Split into
/aaa
/bbb
/ccc

I didn't write that right.
Preg_match ('/(\/\w+) +/i ', '/AAA/BBB/CCC ', $matches);


Reply to discussion (solution)

Be sure to use the regular, I think with explode function is also good AH.

$str = '/AAA/BBB/CCC '; $matches = explode ('/', $str); Explodeecho '/'. $matches [1];  /aaaecho '/'. $matches [2];  /bbbecho '/'. $matches [3];  /cccpreg_match_all (' @\/[a-z]{3}@i ', $str, $matches); Regular echo $matches [0][0];  /aaaecho $matches [0][1];  /bbbecho $matches [0][2];  /ccc


To write like this.
Preg_match_all ('/(\/\w+)/I ', '/AAA/BBB/CCC ', $matches);

$matches [1] that is

3 Floor positive solution, is to match all the requirements, so to use the function Preg_match_all.

Personally feel that there is no need to use the regular, explode () can completely achieve the results you want, why should shejinqiuyuan it, of course, also depends on the actual situation ....

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