Php-PCRE regular expression assertions

Source: Internet
Author: User
PHP extension text processing -- PCRE regular expression syntax 11 -- asserted an asserted is a test of the character before or after the current matching position, which does not actually consume any characters. Simple asserted codes include \ B, \ B, \ A, \ Z, \ z, ^, and $. More complex assertions are encoded as child groups. It has two types: Forward-looking assertions (test from the current position forward) and backward-looking assertions (test from the current position backward ).

An assertion sub-group is still matched in the normal way. The difference is that it will not cause the current match point to change. The positive assertions in the forward-looking assertions (asserted that this match is true) take "(? = "Start with". negative assertions start "(?!" . For example, \ w + (? =;) Match a word followed by a semicolon, but the matching result does not contain a semicolon, foo (?! Bar) matches all "foo" strings that are not followed by "bar. Pay attention to a similar mode (?! Foo) bar. it cannot be used to find all the bar matches that are not "foo". it will find any bar match, because (?! Foo) this assertion will always be TRUE when bar is in the next three characters. This is what the forward-looking assertions need to achieve.

The frontend assertions in the rear-view assertion use "(? <= "Start with". negative assertions start "(?

Multiple assertions (in any order) can appear at the same time. For example (? <= \ D {3 })(?

In this case, check that the first three are digits, and then the second one is checked (the current match point) the first three characters are not "999 ".

Assertions can be nested with any complexity. For example (? <= (?

When a sub-group is asserted, the sub-group is not captured and cannot be modified with quantifiers, because it is meaningless to perform multiple assertions on the same thing. if all assertions contain one capture sub-group, they will be included for the purpose of capturing the sub-group count in the entire mode. However, substring capture can only be used for positive assertions, because it is meaningless for negative assertions.

The maximum number of sub-groups that can be attached to an assertion is 200.

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.