title: Python regex: how to check if a character in a string is within the span of a regex matched substring?
body: <p>I have a regex pattern, which I used on a large piece of text (a single string). Several discontiguous regions of the original text matches the regexp. Now, I'm attempting to build a state machine, to iterate over the text and do different things based on the char at a position, and whether this position is within the span of a regex match.</p>
  
  <p>With RE.finditer(text), I can find all substrings, and extract their spans, thus I have a list of tuples to work with e.g.</p>
  
  <p>(1, 5)
  (10, 15)
  (20, 55),
  etc.</p>
  
  <p>With this information, given the index of the character in my string, I can write an algorithm to see if that character is a part of a regex string. For example, given character 6, i can go through the list of spans and determine that it is not part of a matched substring.</p>
  
  <p>Is there a better way of doing this? </p>
  
  <p>Thanks in advance,</p>
  
  <p>JW</p>