The understanding of the expression in Python is mainly the understanding of the symbol, which is a simple analysis of the regular expression symbols commonly used in Python. The main symbols are:
.
Matches a character by default, does not contain newline characters, and matches line breaks if set Dotall
^
Match beginning
$
Match end of Line
*
Match 0 or more repetitions
+
Match one or more duplicates
?
Match one or 0 duplicates
*?,+?,??
Match by non-greedy pattern
{m},{m,n},{m,n}?
Match M repeats, M to n repeats, M to n repeats in non-greedy mode
\
Escape
[]
[Abc],[a-z][^a-z]
|
or match ' a|b '
(...)
Matching groups
(? 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 content following the matched string needs to be matched
>>> Re.match (R ' Phone (=\d{3}) ', ' phone123 '). Group () ' Phone ' # (?! ...)
Matches the character after the content does not match
>>> Re.match (R ' Phone (?! \d{3}) ', ' phoneabc123 '). Group () ' Phone ' (? <= ...)
Matching strings need to be matched in front of
(?
(? (id/name) Yes-pattern|no-pattern)
\number
\a matches the beginning of a string
\b Match word boundaries
\b
\b's anti-righteousness
\d = [0-9]
\d said [^0-9]
\s said [\t\r\n\f\v]
\s as non-whitespace characters
\w equivalent to [a-za-z0-9]
\w \w's anti-righteousness
\z the end of the matching string