This is the original regex pattern using a negating character group:
0[^1]*1[^2]*2[^3]*3
It will match 0 1 2 3
efficiently with any delimiting character between digits using a lazy quantifier, compared to the greedy 0.*1.*2.*3
which becomes inefficient for long test strings.
How can the same efficiency be achieved when instead of single characters, it should match groups of characters, for example for this test string:
zero one two three
I was thinking to use a negative lookahead, but couldn’t get it to work in an efficient way.
In other words, I'm looking for an efficient regex that matches zero one two three
where the delimiting characters in between can be any combination of characters of any length, so it should also match for example zero-one, two xxx three
.
What's the solution?
(RegEx engine ECMA Script / JavaScript)