Assertion of the regular expression with Zero Width and assertion of the Regular Expression

Source: Internet
Author: User

Assertion of the regular expression with Zero Width and assertion of the Regular Expression

When learning the Regular Expression of. NET, I am confused about the assertion with Zero Width. I took some time to study and take a note.

 

Assertion Overview

(? <= Pattern )(? <! Pattern)STRING(? = Pattern )(?! Pattern): the relative position of various assertions.

? <LookbehindSTRING<Lookahead: NegativeSTRINGForward

=: Positive, Positive, indicating matching

! : Negative, no, indicating no match

(? = Pattern)

Zero-width positive lookahead. If it is not a get match, search for it from the right of the string. It must match pattern. For example (? = 95 | 98 | NT | 2000) "can match" Windows "in" Windows2000 ", but cannot match" Windows "in" Windows3.1 ". Pre-check does not consume characters, that is, after a match occurs, it will continue fromSTRINGThen start the next matching search, instead of starting from after pattern. Same below

(?! Pattern)

Zero-width negative lookahead (0-width negation). If it is not a get match, it is searched from the right side of the string and must not match pattern. For example, "Windows (?! 95 | 98 | NT | 2000) "can match" Windows "in" Windows3.1 ", but cannot match" Windows "in" Windows2000 ".

(? <= Pattern)

Zero-width positive lookbehind. If the string is not retrieved, the string must match pattern on the left .. For example, <= 95 | 98 | NT | 2000) Windows can match Windows in 2000Windows, but cannot match Windows in 3.1Windows ".

(? <! Pattern)

Zero-width negative lookbehind (Zero-width negative), non-get match, search from the left side of the string, must not match pattern. For example, "(? <! 95 | 98 | NT | 2000) Windows can match "Windows" in "3.1Windows", but cannot match "Windows" in "2000Windows ".

Related Article

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.