I feel that this must have been asked somewhere else already, but I cannot find it!
I have a regex that has nested brackets (see below). I need to match ALL occurrences of it in a line and then do something with the pieces. However, I cannot figure out how to reference specific groups from my regex.
Specifically, this is my regex:
(([a-zA-Z][a-zA-Z0-9_\+\-\.]*\.)+\s*[a-zA-Z]{2,6})
I actually don’t care about preserving the contents of the inner brackets I just want to get all the matches for the outer one.
If I use “match” I get one instance and can reference by using the Match Object. However, when I do findall, it does not return Match Objects, it only returns a list.
You’re probably looking for
re.finditer():