Quantcast
Channel: Find the indexes of all regex matches? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Find the indexes of all regex matches?

$
0
0

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 I have the substrings index. My initial thought was to use re to find all the matches and then figure out the range of indexes they represent.

It seems like I should use re with a regex like \"[^\"]+\"|'[^']+' (I'm avoiding dealing with triple quoted and such strings at the moment). When I use findall() I get a list of the matching strings, which is somewhat nice, but I need indexes.

My substring might be as simple as c, and I need to figure out if this particular c is actually quoted or not.


Viewing all articles
Browse latest Browse all 4

Trending Articles