One more PCRE modifier that allows the use of duplicate named groups.
NOTE: only inline version is supported - (?J)
, and must be placed at the start of the pattern.
If you use
/(?J)\w+-(?:new-(?<val>\w+)|\d+-empty-(?<val>[^-]+)-collection)/
the "val" group values will be never empty (will always be set). A similar effect can be achieved with branch reset though.