I\'m parsing strings that could have any number of quoted strings inside them (I\'m parsing code, and trying to avoid PLY). I want to find out if a substring is quoted, and
This is what you want: (source)
re.finditer(pattern, string[, flags])Return an iterator yielding MatchObject instances over all non-overlapping matches for the RE pattern in string. The string is scanned left-to-right, and matches are returned in the order found. Empty matches are included in the result unless they touch the beginning of another match.
You can then get the start and end positions from the MatchObjects.
e.g.
[(m.start(0), m.end(0)) for m in re.finditer(pattern, string)]