I am referring as a follow up on this question here: Regular expression to match two numbers that are not equal
Now my other question scenario is this:
P121324 - T
P1212 - F - we got this covered in the message on link above (no same "sets")
P1221 - F - now new restriction - not even the reversed digits 12 - 21
But, the problem now is that the P string can be very long! – like this:
P121315162324
please notice this is ok since the “sets” are:
12 13 14 15 16 23 24
Now, I could make this in the code (PHP) by checking if there are repetitions, but I was wondering if this can be done with single regex command?
Try this:
If you want the digits to be restricted to [1-6] like in your previous question then change [0-9] to [1-6].
See it working online: rubular
Here is a breakdown of the regular expression:
Explanation of
([0-9])(?!\1)([0-9])(?!(?:..)*(?:\1\2|\2\1))– match one pair:Explanation of
(?:..)*(?:\1\2|\2\1)– try to find the same pair again: