Greedy expression in the regular expression. Solution-php Tutorial

Source: Internet
Author: User
Greedy expression in the regular expression .. PHPcode $ a & lt; B & gt; aaa & lt; B & gt; bbb & lt; B & gt; ccc & lt; B & gt; $ pattern1 & lt; B & gt ;. *? & Lt; B & gt; $ pattern2 ^ & lt; B & gt ;.*? & Lt; B & gt; $; use the greedy expression in the $ p regular expression ..
PHP code
  $ A ='AaaBbbCcc'; $ Pattern1 = '/.*? <\/B>/'; $ pattern2 ='/^.*? <\/B> $ /';


Use $ pattern1 and $ pattern2 to match $ a. The first one can match'Aaa','Bbb','Ccc'These three
However, $ pattern2 can only match the output'AaaBbbCcc', That is .*? The greedy mode of does not work. why ???

Thank you!

------ Solution --------------------
Because you add the ending Character $, it always matches to the end of the string.

Only the first one can be matched even if $ is removed.AaaBecause you have added ^

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.