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!