Find the best match from the regular expression capture group

I would like to find the best match for this regex-capture group. Example:

Regex: (AB | ABC)

Example: ABCDEF

Result: AB

But I would like to find ABC (best suited from the list of options).

How can I do that? (except for replacing both alternatives in the group)?

Thanks for any idea!

+3
source share
1 answer

Try to indicate the best matches in order (for example, the longest lines). Many RE engines prefer first the left in the "impatient assessment" mode. Only POSIX REs indicate that the longest matching alternative will be returned:

http://www.regular-expressions.info/alternation.html

+3
source

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


All Articles