python 正则表达式语法学习笔记

2020-02-26 14:02:50于丽

    (?(id/name)yes|no) Matches yes pattern if the group with id/name matched,
                       the (optional) no pattern otherwise.

The special sequences consist of "" and a character from the list
below.  If the ordinary character is not on the list, then the
resulting RE will match the second character.
    number  Matches the contents of the group of the same number.
    A       Matches only at the start of the string.
    Z       Matches only at the end of the string.
    b       Matches the empty string, but only at the start or end of a word.
    B       Matches the empty string, but not at the start or end of a word.
    d       Matches any decimal digit; equivalent to the set [0-9] in
             bytes patterns or string patterns with the ASCII flag.
             In string patterns without the ASCII flag, it will match the whole
             range of Unicode digits.
    D       Matches any non-digit character; equivalent to [^d].
    s       Matches any whitespace character; equivalent to [ tnrfv] in
             bytes patterns or string patterns with the ASCII flag.
             In string patterns without the ASCII flag, it will match the whole
             range of Unicode whitespace characters.
    S       Matches any non-whitespace character; equivalent to [^s].
    w       Matches any alphanumeric character; equivalent to [a-zA-Z0-9_]
             in bytes patterns or string patterns with the ASCII flag.
             In string patterns without the ASCII flag, it will match the
             range of Unicode alphanumeric characters (letters plus digits
             plus underscore).
             With LOCALE, it will match the set [0-9_] plus characters defined
             as letters for the current locale.
    W       Matches the complement of w.
          Matches a literal backslash.

This module exports the following functions:
    match     Match a regular expression pattern to the beginning of a string.
    fullmatch Match a regular expression pattern to all of a string.
    search    Search a string for the presence of a pattern.