title: Find length of string matched by regex
body: <p>I am trying to write a script to parse a map file generated by a compiler/linker, that looks like this:</p>
  
  <pre><code>%SEGMENT_SECTION
                                                        Start Address  End Address
  --------------------------------------------------------------------------------
  Segment Name: S1_1, Segment Type: .bss                0A000000       0A050F23
  --------------------------------------------------------------------------------
  area1_start.o (.bss)                                  0A000000       0A000003
  ...
  
                                                        Start Address  End Address
  --------------------------------------------------------------------------------
  Segment Name: S2_1, Segment Type: .bss                0A050F24       0A060000
  --------------------------------------------------------------------------------
  area2_start.o (.bss)                                  0A000000       0A000003
  
  ...
  
  %NEXT_SECTION
  </code></pre>
  
  <p>I am currently writing several regular expressions (python's re module) to parse this, but I want to write them in a very easy-to-read way, such that it's very simple to parse.  Essentially:</p>
  
  <pre><code>with open('blah.map') as f:
      text = f.read()
  
  # ... Parse the file to update text to be after the %SEGMENT_SECTION
  
  match = segment_header_re.match(text)
  seg_name, seg_type, start_addr, end_addr = match.groups()
  # ... (Do more with matched values)
  
  text = text[len(match.matched_str):]
  
  # Parse the remainder of text
  </code></pre>
  
  <p>However, I don't know how to get the length of the matched string, as in my <code>match.matched_str</code> pseudo code.  I don't see anything in python's documentation of re.  Is there a better way to do this type of parsing?</p>