Python regexp: get all group's sequence
python, regex
Solution
Your original expression does match the way you want to, it just matches the entire string and doesn't capture individual groups for each separate match. Using a repetition operator ('+', '*', '{m,n}'), the group gets overwritten each time, and only the final match is saved. This is alluded to in the documentation:
If a group matches multiple times, only the last match is accessible.
Problem
I have a regex like this `'^(a|ab|1|2)+$'` and want to get all sequence for this... for example for re.search(reg, 'ab1') I want to get ('ab','1') Equivalent result I can get with `'^(a|ab|1|2)(a|ab|1|2)$'` pattern, but I don't know how many blocks been matched with (pattern)+ Is this possible, and if yes - how?