New syntax » Named capture comparison

There are several different syntaxes used for named capture. Although Python was the first to implement the feature, most libraries have adopted .NET's alternative syntax.

Library Capture Backref in regex Backref in replacement Stored at Backref numbering Multiple groups with same name
XRegExp
  • (?<name>…)
  • (?P<name>…)
  • \k<name>
  • ${name}
result.name Sequential Error‡
.NET
  • (?<name>…)
  • (?'name'…)
  • \k<name>
  • \k'name'
  • ${name}
matcher.Groups('name') Unnamed first, then named Backref to last executed participating group
Perl 5.10
  • (?<name>…)
  • (?'name'…)
  • (?P<name>…)
  • \k<name>
  • \k'name'
  • \k{name}
  • \g{name}
  • (?P=name)
  • $+{name}
$+{name} Sequential Backref to leftmost participating group
PCRE 7.2
  • (?<name>…)
  • (?'name'…)
  • (?P<name>…)
  • \k<name>
  • \k'name'
  • \k{name}
  • \g{name}
  • (?P=name)
N/A Sequential Error
PCRE 7
  • (?<name>…)
  • (?'name'…)
  • (?P<name>…)
  • \k<name>
  • \k'name'
  • (?P=name)
N/A Sequential Error
PCRE 4
  • (?P<name>…)
  • (?P=name)
N/A Sequential Error
Python
  • (?P<name>…)
  • (?P=name)
  • \g<name>
result.group('name') Sequential Error
Oniguruma
  • (?<name>…)
  • (?'name'…)
  • \k<name>
  • \k'name'
  • \k<name>
  • \k'name'
N/A Unnamed groups default to noncapturing when mixed with named groups Backref to rightmost participating group. Backrefs within a regex work as alternation of matches of all preceding groups with the same name, in reverse order.
Java 7
  • (?<name>…)
  • \k<name>
  • ${name}
matcher.group('name') Sequential Error
JGsoft
  • (?<name>…)
  • (?'name'…)
  • (?P<name>…)
  • \k<name>
  • \k'name'
  • (?P=name)
  • ${name}
  • \g<name>
N/A .NET and Python styles, depending on capture syntax Same as .NET
Boost.Regex
  • (?<name>…)
  • (?'name'…)
  • \k<name>
  • \g{name}
? ? ? ?
RE2
  • (?P<name>…)
N/A ? ? ? ?
JRegex
  • ({name}…)
  • {\name}
  • ${name}
matcher.group('name') ? ?

TODO: Add a column comparing the use of capture names in regex conditionals (not supported by XRegExp).

† Added in v2.0.0. Not recommended for use, because support for the (?P<name>…) syntax may be removed in future versions of XRegExp. It is currently supported only to avoid an octal escape versus backreference issue in Opera. Opera supports the Python named capture syntax natively, but does not provide full named capture functionality.

‡ As of v3.0.0.