How to access named capture groups in C++?

1 week ago 10
ARTICLE AD BOX

C++ 20 Draft N4861 says in [re.grammar] (chapter 30.13, page 1517):

The regular expression grammar [...] is that specified by ECMA-262, except as specified below.

ECMA-262 exists in several versions with a new version being released every year lately:

5.1 edition, June 2011 6th edition, June 2015 [...] 14th edition, June 2023 15th edition, June 2024 16th edition, June 2025

Regex in C++ was introduced with C++11, thus 2011, so at the time of C++ specification, people were thinking of ECMA-262 as the 5.1 edition. However, it's worse than that.

Chapter 2, [intro.refs] lists the normative references. In (1.1) we find:

Ecma International, ECMAScript Language Specification, Standard Ecma-262, third edition, 1999.

So, the version of ECMAScript implemented by C++ is version 3 [PDF].

If I understand the grammar rules correctly, we have

Atom :: PatternCharacter . \ AtomEscape CharacterClass ( Disjunction ) ( ? : Disjunction ) ( ? = Disjunction ) ( ? ! Disjunction )

So, there's no named group in the form of ( ? GroupName Disjunction ).

Compare to GroupName within Atom of newer versions:

GroupName :: < RegExpIdentifierName >

Ultimately, this never has worked in C++ and that still doesn't change in C++26, since the latest draft (N5014) still references ECMA-262 third edition in chapter 2, [intro.refs], (1.9), page 2.

Read Entire Article