Questions about regular expression matching causing duplicates

Source: Internet
Author: User
I encountered this situation to match, but each time I matched to the beginning of the repetition:

$file = ' Push_1113_20150105000052430.txt '; $file 2 = ' confirm_push_1114_20150105000052430.txt ';p reg_match ('/^ (get| push|admin). *.txt/', $file, $rs);p reg_match ('/^confirm.*.txt/', $file 2, $rs 2); Echo '
 The result of 

is:

array ([0] = push_1113_20150105000052430.txt [1] = = Push) 
array ([0] = confirm_push_1114_20150105000052430.txt) 

You can see that the first result has a duplicate match to two push, what's going on??

How can I not know, I later various attempts, then changed to do so:

preg_match ('/^[get|push|admin].*.txt/', $file, $rs); 

is to change the parentheses into brackets so that the result is:

array ([0] = push_1113_ 20150105000052430.txt) 

Cause further search is needed, but it is not yet known, but it is certainly due to the difference between () and [].

The above describes the issue of regular expression matching causes duplicates, including the aspects of the content, want to be interested in PHP tutorial friends Helpful.

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