A beginner asks a regular expression-php Tutorial

Source: Internet
Author: User
A beginner asked me a regular expression. I haven't studied it for a long time.

Set
/Aaa/bbb/ccc

Split
/Aaa
/Bbb
/Ccc

I wrote something wrong.
Preg_match ('/(\/\ w +) +/I', '/aaa/bbb/ccc', $ matches );


Reply to discussion (solution)

Do I have to use regular expressions? I think it is good to use the explode function.

$ 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


Write like this
Preg_match_all ('/(\/\ w +)/I', '/aaa/bbb/ccc', $ matches );

$ Matches [1] is

On the third floor, the positive solution must match all compliant requirements. Therefore, use the preg_match_all function.

I personally think that there is no need to use regular expressions. explode () can achieve the desired result. why should I leave it close to the distance? of course, it 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.