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