Python re Regular Expression instance code, pythonre Regular Expression
This article focuses on the reregex expressions of python. The details are as follows.
Concept: Regular Expressions (generic formulas) are expressions used to express a set of strings in a concise manner. The advantage is conciseness.
Application: string matching.
Instance code:
CODEC = 'utf-8' # encoding: UTF-8 import re p = re. compile ("AB") str = "abfffa" # match must match the first letter if p. match (str): print p. match (str ). group () # match must match the first letter. group () prints matching letters out print re. match ('a + B ', 'abvvaabaaab '). group () # differs from match to match the print re letter at any position. search ('a + B ', 'vvvaabaaab '). group () # print re. findall ('a + B ', 'vabmaabnaaab') print re. split (':', 'str1: str2: str3') # The regular expression print ('str1: str2: str3') cannot be matched '). split (':') # separates strings in the form of a + B. It can match the regular expression print re. split ('a + B ', 'vabmaabnaaab ')
Print Information
AB aab ['AB', 'aab', 'aaab'] ['str1', 'str2', 'str3'] ['str1', 'str2 ', 'str3'] ['V', 'M', 'n', '']
Summary
The above is all the content of the python re Regular Expression instance code in this article, I hope to help you. If you are interested, you can continue to refer to other related topics on this site. If you have any shortcomings, please leave a message. Thank you for your support!