Trying to find all possible matches for digits separated by space. Already trying construction with lookahead and lookbehind, but it's not help.
We have string of separated digits (0..99).
We need to find all digital sequences which length greater than 3 and may contain special symbol, for example '1'.
Symbol '1' is universal symbol and can replace any of digits. For example, '2 2 2 2', '1 2 1 2', '2 1 2 2', '2 2 2 1' - is valid matches.
All is ok, except such situations, where symbol '1' owned by two matches:
... 2 2 2 2 1 3 3 3 3 ...
Raw string:
3 1 1 4 4 4 4 1 4 4 5 5 1 5 5 6 7 8 1 9 9 9 9 9 9 1 3 4 5 5 1 1 5 5 6 4 4 4 1 7 1 2 2 2 2 2 2 2 1 11 11 11 11
My regex do almost all fine, except last match:
/(1 ){0,}(\d |\d\d )\2{1,}(1 ){0,}\2{1,}(1 ){0,}/g
Current result (see last match, it must be '1 11 11 11 11'):
1 1 4 4 4 4 1 4 4
5 5 1 5 5
1 9 9 9 9 9 9 1
5 5 1 1 5 5
4 4 4 1
1 2 2 2 2 2 2 2 1
11 11 11 11
Goal:
1 1 4 4 4 4 1 4 4
5 5 1 5 5
1 9 9 9 9 9 9 1
5 5 1 1 5 5
4 4 4 1
1 2 2 2 2 2 2 2 1
1 11 11 11 11
Regexp /(?=((1 ){0,}(\d |\d\d )\3{1,}(1 ){0,}\3{1,}(1 ){0,}))/g
give to much variations of overlapping.
Here sandbox: https://regex101.com/r/VDa6LZ/2
How to find all overlapped matches properly?