Do Python regexes support something like Perl's \G?

I have a Perl regular expression (shown here, though understanding the whole thing isn't hopefully necessary to answering this question) that contains the \G metacharacter. I'd like to translate it into Python, but Python doesn't appear to support \G. What can I do?


Solution 1:

Try these:

import re
re.sub()
re.findall()
re.finditer()

for example:

# Finds all words of length 3 or 4
s = "the quick brown fox jumped over the lazy dogs."
print re.findall(r'\b\w{3,4}\b', s)

# prints ['the','fox','over','the','lazy','dogs']

Solution 2:

Python does not have the /g modifier for their regexen, and so do not have the \G regex token. A pity, really.