Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple groups with the same name regex java?

Is there any regular expression api or library for java that can accept multiple groups with the same name in one pattern?

like image 972
AIA Avatar asked Dec 21 '13 22:12

AIA


1 Answers

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

like image 162
bblue Avatar answered Oct 27 '22 05:10

bblue