How can I obtain the number of overlapping regex matches using Python?
I’ve read and tried the suggestions from this, that and a few other questions, but found none that would work for my scenario. Here it is:
- input example string:
akka - search pattern:
a.*k
A proper function should yield 2 as the number of matches, since there are two possible end positions (k letters).
The pattern might also be more complicated, for example a.*k.*a should also be matched twice in akka (since there are two k‘s in the middle).
Yes, it is ugly and unoptimized but it seems to be working. This is a simple try of all possible but unique variants
test: