3.2.1 Regular Expression syntax (1), 3.2.1 Regular Expression

Source: Internet
Author: User

3.2.1 Regular Expression syntax (1), 3.2.1 Regular Expression

(?...)

This syntax rule is an extension of the previous syntax. It can be replaced with a specific character at the question mark position.

Example:

Print ('(?...) ')

M = re. findall (R' (a...) ', r'abcdefaghijk ')

If m:

Print (m)

The output result is as follows:

(?...)

['Abcd', 'aghi']


(? #...)

Comment out the brackets, which does not work. Skip these rules during regular expression analysis.

Example:

Print ('(? # )')

M = re. findall (U '(? # A) I ', u'ailmsux aaaadefagaiLmsuxhijk ')

If m:

Print (m)

The output result is as follows:

(? #)

['I', 'I', 'I']

 

(? = ...)

Forward recognition mode. When the forward character matches the character in the equal sign, it is considered to be matched, but these characters are not skipped. For example, Isaac (? = Asimov), the Isaac is recognized only when the Asimov character is reached after the Isaac character, but the Asimov won't jump over.

Example:

Import re

 

 

Print ('isaac (? = Asimov )')

M = re. findall (u'isaac (? = Asimov) ', u'abcdisaacasimovttttt ')

If m:

Print (m)

The output result is as follows:

Isaac (? = Asimov)

['Isaac ']



Cai junsheng QQ: 9073204 Shenzhen

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.