Positive pre-checking and reverse pre-checking of regular expressions

Source: Internet
Author: User

Forward Pre-check:
1. Positive Pre-check: (? =)
For example:
Foo (? =bar)//Match foo with bar at the back
It can match: Foobar, Foo in Abcfoobar
But can't match: Foo in FOOABC

2. Positive negative pre-check: (?!)
For example:
Foo (?! BAR)//Match foo with no bar behind
It can match: foo123
But does not match: Foobar


Negative to pre-check
1. Negative positive pre-check (? <=)
For example:
(? <=foo) bar//Match bar with Foo above
It can match: Foobar, bar in 123foobar
Can not match: bar in 123bar

2. Negative negative pre-check (? <!)
For example:
(? <!foo) bar//Match bar with no Foo in front
It can match: bar in 123bar
Cannot be matched: Foobar, bar in 123foobar 
pre-check can also be nested &NBSP;
For example: 
(? <= (? <!foo) bar) Baz        //matches a Baz, which is preceded by a bar, But the front of bar can not be foo
 
 
(? <=\d{3} ... (? <!999)) Foo        //matches a foo, which is preceded by three non-999 characters, three characters before three digits
It can match 123123foo, 111cdefoo, 111c2cfoo   inside of FOO
 
Note: All pre-checks are non-fetch matches and do not consume characters. That is, after a match occurs, the next matching search starts immediately after the last match, rather than starting with the character that contains the pre-check.

Reprint: http://3721myth.blog.163.com/blog/static/31831706201132111234121/

Positive pre-checking and reverse pre-checking of regular expressions

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.