The main understanding of the expression of Python is the understanding of the symbol, which is the simple analysis of regular expression symbols commonly used in Python. The main symbols are:
.
Matches a character by default, does not contain line breaks, and matches line breaks if set Dotall
^
Match the beginning of a line
$
Match end of Line
*
Match 0 or more duplicates
+
Match one or more duplicates
?
Match one or 0 duplicates
*?,+?,??
Match in non-greedy mode
{m},{m,n},{m,n}?
Match M Repeat, M to n repeat, m to n repeat in non greedy mode
\
Escape
[]
[Abc],[a-z][^a-z]
|
or match ' a|b '
(...)
Match Group
(? ilmsux)
(?:...) (? P<name> ...)
>>> Re.match ('? P<NAME>ABC) {2} ', ' Abcabc '). Groupdict ()
{' name ': ' ABC '}
(? P=name)
>>> Re.match (R ' (?) P<NAME>ABC)----(? P=name) ', ' ABC----ABC '). Group ()
' ABC----ABC '
(? # ...) #后面的内容为注释 (?
= ...)
Matches the contents of the string that need to match
>>> Re.match (R ' Phone (? =\d{3}) ', ' phone123 '). Group ()
' phone ' #
(?!) ...)
Matching characters do not match the contents after
>>> Re.match (R ' Phone (?!) \d{3}) ', ' phoneabc123 '. Group ()
' phone '
(? <= ...)
Matching strings need to match before
(?<!...) Matching characters cannot match before
(? (id/name) Yes-pattern|no-pattern)
\number
\a matches the beginning of a string
\b Match word boundaries
\b
The \b of the anti-righteousness
\d said [0-9]
\d says [^0-9]
\s says [\t\r\n\f\v]
\s is not a blank character
\w equivalent to [a-za-z0-9]
The \w of the \w of the Yi-
End of \z matching string