How to find all possibly overlapping matches?

K

kj

re.findall finds all non-overlapping matches, but what if one wants
all (maximal) matches, even those that overlap?

All the solutions I can come up involve calling re.search iteratively,
each time giving it a pos parameter starting just after the start
of the previous match.

Is there a built-in solution to such a task?

TIA!

kynn
 
M

MRAB

kj said:
re.findall finds all non-overlapping matches, but what if one wants
all (maximal) matches, even those that overlap?

All the solutions I can come up involve calling re.search iteratively,
each time giving it a pos parameter starting just after the start
of the previous match.

Is there a built-in solution to such a task?
Not in the re module.

It has been requested and is in my regex implementation at
http://bugs.python.org/issue2636 if you want to try that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top