I’m trying to write a regex, where the same group of terms is looked for twice, but I want to avoid matching the same term twice. If a term is found in the first group, it should not be matched in the second group.
/(a|b).*?(a|b)/
This would match:
a a
a b
b a
b b
But I do not want to match a a
and b b
, only a b
and b a
. The method should work with any number of terms, (a|b)
is just an example but it could be something like:
/(anna|beat|chris|dirk).*?(anna|beat|chris|dirk)/