Is there a preference for one match in Regex when matching matches?

I have a regex that matches the condition x OR y. Sometimes these coincidences 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> Soup Alphabet

Matches:

Dedicated matching 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 the match.

+3
source share
1

:

X[^\w]*>|>[^\w]*X(?![^\w]*>)

. "> X", " >", "X >".

+8

Source: https://habr.com/ru/post/1705148/


All Articles