Detailed explanation of the full match function using regular expressions in python, python Regular Expressions

Source: Internet
Author: User

Detailed explanation of the full match function using regular expressions in python, python Regular Expressions

Full matching using regular expressions in python

There are many matches in python, such as the search () function at any location and the match () function at the search boundary. Now you need to learn a full match function, that is, the search character matches all the content, and it is the fullmatch () function.

Example:

# Python 3.6 # Cai junsheng # http://blog.csdn.net/caimouse/article/details/51749579#import retext = 'this is some text -- with punctuation. 'pattern' = 'is 'print ('text: ', Text) print ('pattern', pattern) m = re. search (pattern, text) print ('search: ', m) s = re. fullmatch (pattern, text) print ('full match: ', s) text = 'is 'print ('text:', Text) s = re. fullmatch (pattern, text) print ('full match: ', s) text = 'iss' print ('text:', Text) s = re. fullmatch (pattern, text) print ('full match: ', s)

The output is as follows:

Text    : This is some text -- with punctuation.Pattern  : isSearch   : <_sre.SRE_Match object; span=(2, 4), match='is'>Full match : NoneText    : isFull match : <_sre.SRE_Match object; span=(0, 2), match='is'>Text    : issFull match : None

If you have any questions, please leave a message or go to the community on this site for discussion. Thank you for reading this article. Thank you for your support!

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.