What language/implementation/runtime are you using?
PCRE enables multiple named capture groups with the (?J)
mode modifier, but in many implementations (Perl included), you can't meaningfully use duplicate capture groups unless they are part of separate alternatives of the regex.
i.e. in Perl and PHP: The match for the following will be unusable when trying to match "... ERROR"
:
/(?J)(?<type>INFO)?.*?(?<type>ERROR)?/
That's because the first capture group "wins" and is empty. (See below)
However...
/(?J)(?<type>INFO|SEVERE)\b.*|.*\b(?<type>ERROR|WARN)/
will work
I wasn't entirely clear on what you were trying to match, so I'm not sure if the above regular expressions are in any way representative of what you're doing
More on duplicate named groups
From https://www.regular-expressions.info/named.html
... In Perl, a backreference matches the text captured by the leftmost group in the regex with that name that matched something...
So in Perl and Ruby, you can only meaningfully use groups with the same name if they are in separate alternatives in the regex, so that only one of the groups with that name could ever capture any text. Then backreferences to that group sensibly match the text captured by the group.