This article mainly introduces Python's common Regular Expression symbols, which are very practical. If you need them, you can refer to the comprehension of Regular Expressions in Python, mainly understanding the symbols, this article analyzes the regular expression symbols commonly used in Python. The main symbols are:
.
By default, one character is matched, excluding line breaks. If DOTALL is set, the line breaks are matched.
^
Match the beginning of a row
$
Match the end of a row
*
Matches 0 or multiple duplicates.
+
Match one or more duplicates
?
Matches one or zero duplicates.
*?, + ?,??
Match by non-Greedy Mode
{M}, {m, n}, {m, n }?
Match m duplicates, m to n duplicates, and m to n duplicates in non-Greedy mode.
\
Escape
[]
[Abc], [a-z] [^ a-z]
|
Or match 'a | B'
(...)
Matching Group
(? ILmsux )(? :...)(? P
...) >>> Re. match ('(? P
Abc) {2} ', 'abcabc'). groupdict () {'name': 'abc '}(? P = name) >>> re. match (R '(? P
Abc )----(? P = name) ', 'abc ---- abc'). group () 'abc ---- abc '(? #...) # The following content is a comment (? = ...)
The content following the matched string needs to be matched.
>>> re.match(r'phone(?=\d{3})','phone123').group()'phone'#(?!...)
The matched characters cannot match
>>> re.match(r'phone(?!\d{3})','phoneabc123').group()'phone'(?<=...)
Match before the matched string
(?
(? (Id/name) yes-pattern | no-pattern)
\ Number
\ A matches the start of A string
\ B match word boundary
\ B
\ B's antsense
\ D indicates [0-9]
\ D indicates [^ 0-9]
\ S indicates [\ t \ r \ n \ f \ v]
\ S is a non-white space character
\ W is equivalent to [a-zA-Z0-9]
\ W \ w antsense
\ Z: End of matching string