The re Module (cont)

Match Objects

  • Contain information about the match itself
  • But it is based on a notion of "groups"

Grouping Rules

     (\d+)\.(\d*)
  • This regular expression has 3 groups
     group 0  : The entire regular expression
     group 1  : The (\d+) part
     group 2  : The (\d*) part 
  • Group numbers are assigned left to right in the pattern

Obtaining match information

     m.group(n)    # Return text matched for group n
     m.start(n)    # Return starting index for group n
     m.end(n)      # Return ending index for group n 
<<< O'Reilly OSCON 2000, Advanced Python Programming, Slide 29
July 17, 2000, beazley@cs.uchicago.edu
>>>