: This article mainly introduces repeated items caused by regular expression matching. if you are interested in the PHP Tutorial, please refer to it. I encountered such a situation to match, but each time I matched the beginning of the repeat:
$ File = 'push_1113_20150105000052430.txt '; $ file2 = 'confirm_push_1114_20150105000052430.txt'; preg_match ('/^ (get | push | admin ). *. txt/', $ file, $ rs); preg_match ('/^ confirm. *. txt/', $ file2, $ rs2); echo''; Print_r ($ rs); echo'';print_r($rs2);exit;
The result is:
Array( [0] => push_1113_20150105000052430.txt [1] => push)Array( [0] => confirm_push_1114_20150105000052430.txt)
We can see that the first result matches two pushes repeatedly. what is the problem ??
I don't know how it works. I tried it and changed it to this:
preg_match('/^[get|push|admin].*.txt/', $file, $rs);
The parentheses are changed to brackets. The result is as follows:
Array( [0] => push_1113_20150105000052430.txt)
The reason still needs to be further searched. it is unknown yet, but it must be because of the difference between () and.
The above introduces the problem of repeated items caused by regular expression matching, including some content, and hope to be helpful to friends who are interested in PHP tutorials.