I'd like to find the best match with a given regex-capturegroup. Example:
Regex: (AB|ABC)
Sample: ABCDEF
Result: AB
But I'd like to find ABC (the best fit from the option-list).
How can this be done? (except of exchanging the both alternatives in the group)?
Thanks for any idea!
Try specifying your best matches in order (e.g., longest strings first). Many RE engines prefer left-most first in their "eager evaluation" mode. Only POSIX REs mandate that the longest matching alternate be returned:
http://www.regular-expressions.info/alternation.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With