In words, I would describe the problem as "match A
or B
, match foo
, and then match A
or B
that did NOT match previously".
I can do it with the following regex:
AfooB|BfooA
I'm wondering if there is a more efficient way to do this? I know how to reference a captured group using the "\"
and then the group number. In this case I would like to apply something like to say "not the option that matched in the captured group" (and still be restricted to only match the other possible matches for that group).
The reason I'm looking for something more efficient than simply "AfooB|BfooA"
is that in my case"foo"
is a very long pattern and I would prefer to reduce duplication if possible.