I have a regular expression that matches x OR y condition. Sometimes those matches overlap and I want to give preference to one of the conditions.
Here is my test case.
Regex:
X[^\w]*\>|\>[^\w]*X
Input:
Soup > X > Alphabet
Alphabet Soup > X
X > Alphabet Soup
Matches:
Highlighted match results http://i.friendfeed.com/b55db94551503bf13d16f944fc56d9ff56676b4f
The first highlighted match (yellow) should be X > instead of > X but I’m not sure how to give preference to one of the matches given an overlap.
This should do it:
A negative look-ahead after the low-prioritized alternative. When it finds
'> X', but there is a' >'after it, it should be skipped in favor of'X >'.