The re Module

General idea

  • Regular expressions are specified using syntax described.
  • Compiled into a regular expression "object".
  • This is used to perform matching and replacement operations.

Example

     import re
     pat = r'(\d+)\.(\d*)'    # My pattern
     r = re.compile(pat)      # Compile it
     m = r.match(s)           # See if string s matches
     if m: 
         # Yep, it matched
         ...
     else:
         # Nope.
         ... 
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 27
July 17, 2000, beazley@cs.uchicago.edu
>>>