While the regex parser walks down the string each position gets consumed. To extract substrings with the same starting position it would be needed to look behind and capture matches towards start. Capturing overlapping matches needs to be done inside a lookaround for not consuming the captured parts. Python re
does not support lookbehinds of variable length but PyPI regex does.
import regex as re
res = re.findall(r"(?<=(.*\d(?:\.|$)))", s)
See this Python demo at tio.run or a Regex101 demo (captures will be in the first group).
In PyPI there is even an overlapped=True
option which lets avoid to capture inside the lookbehind. Together with (?r)
another interesting flag for doing a reverse search it could also be achieved.
res = re.findall(r'(?r).*\d(?:\.|$)', s, overlapped=True)[::-1]
The result just needs to be reversed afterwards for receiving the desired order: Python demo
Using standard re
an idea can be to reverse the string and do capturing inside a lookahead. The needed parts get captured from the reversed string and finally each list item gets reversed again before reversing the entire list. I don't know if this is worth the effort but it seems to work as well.
res = [x[::-1] for x in re.findall(r'(?=((?:\.\d|^).*))', s[::-1])][::-1]
Another Python demo at tio.run or a Regex101 demo (shows matching on the reversed string).