Duplicate items caused by regular expression matching

Source: Internet
Author: User
: 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.

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.