title: map string position to line number in regex output
body: <p>I'm working on a "grep-like" utility in Python for searching Oracle source code files.  Coding standards have changed over time, so trying to find something like "all deletes from table a.foo" could span multiple lines, or not, depending on the age of that piece of code:</p>
  
  <pre><code>s = """-- multiline DDL statement
  DELETE
      a.foo f
  WHERE
      f.bar = 'XYZ';
  
  DELETE a.foo f
  WHERE f.bar = 'ABC';
  
  DELETE a.foo WHERE bar = 'PDQ';
  """
  
  import re
  
  p = re.compile( r'\bDELETE\b.+?a\.foo', re.MULTILINE | re.DOTALL )
  
  for m in re.finditer( p, s ):
      print s[ m.start() : m.end() ]
  </code></pre>
  
  <p>This outputs:</p>
  
  <pre><code>DELETE
      a.foo
  DELETE a.foo
  DELETE a.foo
  </code></pre>
  
  <p>What I want:</p>
  
  <pre><code>[2] DELETE
  [3]     a.foo
  [7] DELETE a.foo
  [10] DELETE a.foo
  </code></pre>
  
  <p>Is there a quick/simple/builtin way to map string indices to line numbers?</p>