I can’t tell what you really want. Are you trying to understand incremental matches?
Perhaps you need to learn to use anchors properly. Just as you should never use the Java misnamed and deceptive matches
method instead of its find
method, you should probably eschew Python’s match
method in favor of search
, and for precisely the same reason.
Another possibility is to rewrite your pattern with optional portions that you can then inspect the success of.
Or perhaps you should look into the fuzzy matching support in Matthew Barnett’s replacement regex
library, which you really should be using instead of the crufty old re
.
I can’t tell what you’re realy asking, because you haven’t given examples of desired input and output.
EDIT
Perhaps you need nothing more complex than (?=.*(?:ab|bc)).*a?b?c?
, or spaced out:
(?x)
(?= .* (?: ab | bc) )
.*
a? b? c?
If you put a
, b
, and c
into recursible subgroups, you wouldn’t even have to repeat yourself.