Python 0 wide Negative lookahead assertion (experience)

Source: Internet
Author: User

0 wide (surround) negative lookahead assertion (negative Forward View assertion): (?! EXP), which asserts that the expression cannot be matched before this position, so it will only match the location where the suffix exp does not exist.

0 width, indicating that it is not a character width.

Ex:

1>>>Import re2>>>['sale%s'% E.group (2) forEinch 3Re.finditer (R'(? m) ^\s+ (?! noreply) (\w+) (@\w+\.\w+)',4          " "5 [email protected]6 [email protected]7 [email protected]8 [email protected]9               " ")]Ten['[email protected]','[email protected]','[email protected]']

Wherein, R ' (? m) ^\s+ (?! noreply) (\w+) (@\w+\.\w+) '

(? m) on behalf of multiline, multi-line search.

^\s+ represents the number of spaces placed at the beginning of a sentence.

(?! Noreply) represents an expression that cannot be matched if there is a suffix noreply.

(\w+) Match mail user name

(\w+) (@\w+\.\w+) match mail domain name

Group (1) represents user name (below)

Group (2) represents the domain name

['sale%s'% E.group (1) forEinchRe.finditer (R'(? m) ^\s+ (?! noreply) (\w+) (@\w+\.\w+)',         " "[email protected] [email protected] [email protected] [email prot Ected]" ")]['Salesales','Salepostmaster','Saleeng']

Thank:

http://blog.csdn.net/firetaker/article/details/5603756

http://blog.csdn.net/binjly/article/details/12152235

Python 0 wide Negative lookahead assertion (experience)

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.