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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top