Is there any regular expression api or library for java that can accept multiple groups with the same name in one pattern?
This is a very old question, but google brought me here, I found a solution for PHP using the /J
modifier. All details explained here: http://www.rexegg.com/regex-capture.html#dupe_names
In .NET, PCRE (C, PHP, R…), Perl and Ruby, you can use the same group name at various places in your pattern. (In PCRE you need to use the (?J) modifier or PCRE_DUPNAMES option.) In these engines, this regex would be valid:
:(?<token>\d+)|(?<token>\d+)#
Working example here https://regex101.com/r/h7HJXj/1
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