Regular Expressions

Special characters

     \number     Matches text matched by previous group
     \A          Matches start of string
     \b          Matches empty string at beginning or end of word
     \B          Matches empty string not at begin or end of word
     \d          Matches any decimal digit
     \D          Matches any non-digit
     \s          Matches any whitespace
     \S          Matches any non-whitespace
     \w          Matches any alphanumeric character
     \W          Matches characters not in \w
     \Z          Match at end of string.
     \\          Literal backslash

Raw strings

  • Because of backslashes and special characters, raw strings are used.
  • Raw strings don't interpret backslash as an escape code
     expr = r'(\d+)\.(\d*)'     # Matches numbers like 3.4772 
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 26
July 17, 2000, beazley@cs.uchicago.edu
>>>