[re]
# 28 Text processing library [[text]](./#text)
## 28.6 Regular expressions library [re]
### [28.6.1](#general) General [[re.general]](re.general)
[1](#general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L8998)
Subclause [re] describes components that C++ programs may use to
perform operations involving regular expression matching and
searching[.](#general-1.sentence-1)
[2](#general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9003)
The following subclauses describe a basic regular expression class template and its
traits that can handle char-like ([[strings.general]](strings.general "27.1 General")) template arguments,
two specializations of this class template that handle sequences of char and wchar_t,
a class template that holds the
result of a regular expression match, a series of algorithms that allow a character
sequence to be operated upon by a regular expression,
and two iterator types for
enumerating regular expression matches, as summarized in Table [117](#tab:re.summary "Table 117: Regular expressions library summary")[.](#general-2.sentence-1)
Table [117](#tab:re.summary) — Regular expressions library summary [[tab:re.summary]](./tab:re.summary)
| [ð](#tab:re.summary-row-1) | **Subclause** | **Header** |
| --- | --- | --- |
| [ð](#tab:re.summary-row-2)
[[re.req]](#req "28.6.2 Requirements") | Requirements | |
| [ð](#tab:re.summary-row-3)
[[re.const]](#const "28.6.4 Namespace std::regex_constants") | Constants | |
| [ð](#tab:re.summary-row-4)
[[re.badexp]](#badexp "28.6.5 Class regex_error") | Exception type | |
| [ð](#tab:re.summary-row-5)
[[re.traits]](#traits "28.6.6 Class template regex_traits") | Traits | |
| [ð](#tab:re.summary-row-6)
[[re.regex]](#regex "28.6.7 Class template basic_regex") | Regular expression template | |
| [ð](#tab:re.summary-row-7)
[[re.submatch]](#submatch "28.6.8 Class template sub_match") | Submatches | |
| [ð](#tab:re.summary-row-8)
[[re.results]](#results "28.6.9 Class template match_results") | Match results | |
| [ð](#tab:re.summary-row-9)
[[re.alg]](#alg "28.6.10 Regular expression algorithms") | Algorithms | |
| [ð](#tab:re.summary-row-10)
[[re.iter]](#iter "28.6.11 Regular expression iterators") | Iterators | |
| [ð](#tab:re.summary-row-11)
[[re.grammar]](#grammar "28.6.12 Modified ECMAScript regular expression grammar") | Grammar | |
[3](#general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9026)
The ECMAScript Language Specification described in Standard Ecma-262
is called [*ECMA-262*](#def:ECMA-262 "28.6.1 General [re.general]") in this Clause[.](#general-3.sentence-1)
### [28.6.2](#req) Requirements [[re.req]](re.req)
[1](#req-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9032)
This subclause defines requirements on classes representing regular
expression traits[.](#req-1.sentence-1)
[*Note [1](#req-note-1)*:
The class templateregex_traits, defined in [[re.traits]](#traits "28.6.6 Class template regex_traits"),
meets these requirements[.](#req-1.sentence-2)
â *end note*]
[2](#req-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9041)
The class template basic_regex, defined in[[re.regex]](#regex "28.6.7 Class template basic_regex"), needs a set of related types and
functions to complete the definition of its semantics[.](#req-2.sentence-1)
These types
and functions are provided as a set of member [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]")*s* and functions
in the template parameter traits used by the basic_regex class
template[.](#req-2.sentence-2)
This subclause defines the semantics of these
members[.](#req-2.sentence-3)
[3](#req-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9050)
To specialize class template basic_regex for a character
container CharT and its related regular
expression traits class Traits, use basic_regex[.](#req-3.sentence-1)
[4](#req-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9055)
In the following requirements,
- [(4.1)](#req-4.1)
X denotes a traits class defining types and functions
for the character container type charT;
- [(4.2)](#req-4.2)
u is an object of type X;
- [(4.3)](#req-4.3)
v is an object of type const X;
- [(4.4)](#req-4.4)
p is a value of type const charT*;
- [(4.5)](#req-4.5)
I1 and I2 are input iterators ([[input.iterators]](input.iterators "24.3.5.3 Input iterators"));
- [(4.6)](#req-4.6)
F1 and F2 are forward iterators ([[forward.iterators]](forward.iterators "24.3.5.5 Forward iterators"));
- [(4.7)](#req-4.7)
c is a value of type const charT;
- [(4.8)](#req-4.8)
s is an object of type X::string_type;
- [(4.9)](#req-4.9)
cs is an object of type const X::string_type;
- [(4.10)](#req-4.10)
b is a value of type bool;
- [(4.11)](#req-4.11)
I is a value of type int;
- [(4.12)](#req-4.12)
cl is an object of type X::char_class_type; and
- [(4.13)](#req-4.13)
loc is an object of type X::locale_type[.](#req-4.sentence-1)
[5](#req-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9091)
A traits class X meets the regular expression traits requirements
if the following types and expressions are well-formed and have the specified
semantics[.](#req-5.sentence-1)
[ð](#req-itemdecl:1)
`typename X::char_type
`
[6](#req-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9101)
*Result*: charT,
the character container type used in the implementation of class
template basic_regex[.](#req-6.sentence-1)
[ð](#req-itemdecl:2)
`typename X::string_type
`
[7](#req-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9113)
*Result*: basic_string
[ð](#req-itemdecl:3)
`typename X::locale_type
`
[8](#req-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9123)
*Result*: A copy constructible type
that represents the locale used by the traits class[.](#req-8.sentence-1)
[ð](#req-itemdecl:4)
`typename X::char_class_type
`
[9](#req-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9134)
*Result*: A bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))
representing a particular character classification[.](#req-9.sentence-1)
[ð](#req-itemdecl:5)
`X::length(p)
`
[10](#req-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9145)
*Result*: size_t
[11](#req-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9149)
*Returns*: The smallest i such that p[i] == 0[.](#req-11.sentence-1)
[12](#req-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9153)
*Complexity*: Linear in i[.](#req-12.sentence-1)
[ð](#req-itemdecl:6)
`v.translate(c)
`
[13](#req-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9163)
*Result*: X::char_type
[14](#req-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9167)
*Returns*: A character such that for any character d that is to be considered equivalent to c then v.translate(c) == v.translate(d)[.](#req-14.sentence-1)
[ð](#req-itemdecl:7)
`v.translate_nocase(c)
`
[15](#req-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9179)
*Result*: X::char_type
[16](#req-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9183)
*Returns*: For all characters C that are to be considered equivalent to c when comparisons are to be performed without regard to case,
then v.translate_nocase(c) == v.translate_nocase(C)[.](#req-16.sentence-1)
[ð](#req-itemdecl:8)
`v.transform(F1, F2)
`
[17](#req-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9195)
*Result*: X::string_type
[18](#req-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9199)
*Returns*: A sort key for the character sequence designated by
the iterator range [F1, F2) such that
if the character sequence [G1, G2) sorts before
the character sequence [H1, H2)
then v.transform(G1, G2) < v.transform(H1, H2)[.](#req-18.sentence-1)
[ð](#req-itemdecl:9)
`v.transform_primary(F1, F2)
`
[19](#req-19)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9213)
*Result*: X::string_type
[20](#req-20)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9219)
*Returns*: A sort key for the character sequence designated by
the iterator range [F1, F2) such that
if the character sequence [G1, G2) sorts before
the character sequence [H1, H2)
when character case is not considered
then v.transform_primary(G1, G2) < v.transform_primary(H1, H2)[.](#req-20.sentence-1)
[ð](#req-itemdecl:10)
`v.lookup_collatename(F1, F2)
`
[21](#req-21)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9234)
*Result*: X::string_type
[22](#req-22)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9238)
*Returns*: A sequence of characters that represents the collating element
consisting of the character sequence designated by
the iterator range [F1, F2)[.](#req-22.sentence-1)
Returns an empty string
if the character sequence is not a valid collating element[.](#req-22.sentence-2)
[ð](#req-itemdecl:11)
`v.lookup_classname(F1, F2, b)
`
[23](#req-23)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9252)
*Result*: X::char_class_type
[24](#req-24)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9256)
*Returns*: Converts the character sequence designated by the iterator range
[F1, F2) into a value of a bitmask type that can
subsequently be passed to isctype[.](#req-24.sentence-1)
Values returned from lookup_classname can be bitwise or'ed together;
the resulting value represents membership
in either of the corresponding character classes[.](#req-24.sentence-2)
If b is true, the returned bitmask is suitable for
matching characters without regard to their case[.](#req-24.sentence-3)
Returns 0 if the character sequence is not the name of
a character class recognized by X[.](#req-24.sentence-4)
The value returned shall be independent of
the case of the characters in the sequence[.](#req-24.sentence-5)
[ð](#req-itemdecl:12)
`v.isctype(c, cl)
`
[25](#req-25)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9278)
*Result*: bool
[26](#req-26)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9282)
*Returns*: Returns true if character c is a member of
one of the character classes designated by cl,false otherwise[.](#req-26.sentence-1)
[ð](#req-itemdecl:13)
`v.value(c, I)
`
[27](#req-27)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9294)
*Result*: int
[28](#req-28)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9298)
*Returns*: Returns the value represented by the digit *c* in base*I* if the character *c* is a valid digit in base *I*;
otherwise returns -1[.](#req-28.sentence-1)
[*Note [2](#req-note-2)*:
The value of *I* will only be 8, 10, or 16[.](#req-28.sentence-2)
â *end note*]
[ð](#req-itemdecl:14)
`u.imbue(loc)
`
[29](#req-29)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9313)
*Result*: X::locale_type
[30](#req-30)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9318)
*Effects*: Imbues u with the locale loc and
returns the previous locale used by u if any[.](#req-30.sentence-1)
[ð](#req-itemdecl:15)
`v.getloc()
`
[31](#req-31)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9329)
*Result*: X::locale_type
[32](#req-32)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9333)
*Returns*: Returns the current locale used by v, if any[.](#req-32.sentence-1)
[33](#req-33)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9338)
[*Note [3](#req-note-3)*:
Class template regex_traits meets the requirements for a
regular expression traits class when it is specialized forchar or wchar_t[.](#req-33.sentence-1)
This class template is described in
the header [](#header:%3cregex%3e "28.6.3 Header synopsis [re.syn]"), and is described in [[re.traits]](#traits "28.6.6 Class template regex_traits")[.](#req-33.sentence-2)
â *end note*]
### [28.6.3](#syn) Header synopsis [[re.syn]](re.syn)
[ð](#header:%3cregex%3e)
#include // see [[compare.syn]](compare.syn "17.12.1 Header synopsis")#include // see [[initializer.list.syn]](initializer.list.syn "17.11.2 Header synopsis")namespace std {// [[re.const]](#const "28.6.4 Namespace std::regex_constants"), regex constantsnamespace regex_constants {using syntax_option_type = *T1*; using match_flag_type = *T2*; using error_type = *T3*; }// [[re.badexp]](#badexp "28.6.5 Class regex_error"), class regex_errorclass regex_error; // [[re.traits]](#traits "28.6.6 Class template regex_traits"), class template regex_traitstemplate struct regex_traits; // [[re.regex]](#regex "28.6.7 Class template basic_regex"), class template basic_regextemplate> class basic_regex; using regex = basic_regex; using wregex = basic_regex; // [[re.regex.swap]](#regex.swap "28.6.7.6 Swap"), basic_regex swaptemplatevoid swap(basic_regex& e1, basic_regex& e2); // [[re.submatch]](#submatch "28.6.8 Class template sub_match"), class template sub_matchtemplateclass sub_match; using csub_match = sub_match; using wcsub_match = sub_match; using ssub_match = sub_match; using wssub_match = sub_match; // [[re.submatch.op]](#submatch.op "28.6.8.3 Non-member operators"), sub_match non-member operatorstemplatebool operator==(const sub_match& lhs, const sub_match& rhs); templateauto operator<=>(const sub_match& lhs, const sub_match& rhs); templatebool operator==(const sub_match& lhs, const basic_string::value_type, ST, SA>& rhs); templateauto operator<=>(const sub_match& lhs, const basic_string::value_type, ST, SA>& rhs); templatebool operator==(const sub_match& lhs, const typename iterator_traits::value_type* rhs); templateauto operator<=>(const sub_match& lhs, const typename iterator_traits::value_type* rhs); templatebool operator==(const sub_match& lhs, const typename iterator_traits::value_type& rhs); templateauto operator<=>(const sub_match& lhs, const typename iterator_traits::value_type& rhs); template basic_ostream&operator<<(basic_ostream& os, const sub_match& m); // [[re.results]](#results "28.6.9 Class template match_results"), class template match_resultstemplate>>class match_results; using cmatch = match_results; using wcmatch = match_results; using smatch = match_results; using wsmatch = match_results; // match_results comparisonstemplatebool operator==(const match_results& m1, const match_results& m2); // [[re.results.swap]](#results.swap "28.6.9.8 Swap"), match_results swaptemplatevoid swap(match_results& m1,
match_results& m2); // [[re.alg.match]](#alg.match "28.6.10.2 regex_match"), function template regex_matchtemplatebool regex_match(BidirectionalIterator first, BidirectionalIterator last,
match_results& m, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_match(BidirectionalIterator first, BidirectionalIterator last, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_match(const charT* str, match_results& m, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_match(const basic_string& s,
match_results::const_iterator,
Allocator>& m, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_match(const basic_string&&,
match_results::const_iterator,
Allocator>&, const basic_regex&,
regex_constants::match_flag_type = regex_constants::match_default) = delete; templatebool regex_match(const charT* str, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_match(const basic_string& s, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); // [[re.alg.search]](#alg.search "28.6.10.3 regex_search"), function template regex_searchtemplatebool regex_search(BidirectionalIterator first, BidirectionalIterator last,
match_results& m, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_search(BidirectionalIterator first, BidirectionalIterator last, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_search(const charT* str,
match_results& m, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_search(const charT* str, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_search(const basic_string& s, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_search(const basic_string& s,
match_results::const_iterator,
Allocator>& m, const basic_regex& e,
regex_constants::match_flag_type flags = regex_constants::match_default); templatebool regex_search(const basic_string&&,
match_results::const_iterator,
Allocator>&, const basic_regex&,
regex_constants::match_flag_type = regex_constants::match_default) = delete; // [[re.alg.replace]](#alg.replace "28.6.10.4 regex_replace"), function template regex_replacetemplate OutputIterator
regex_replace(OutputIterator out,
BidirectionalIterator first, BidirectionalIterator last, const basic_regex& e, const basic_string& fmt,
regex_constants::match_flag_type flags = regex_constants::match_default); template OutputIterator
regex_replace(OutputIterator out,
BidirectionalIterator first, BidirectionalIterator last, const basic_regex& e, const charT* fmt,
regex_constants::match_flag_type flags = regex_constants::match_default); template basic_string regex_replace(const basic_string& s, const basic_regex& e, const basic_string& fmt,
regex_constants::match_flag_type flags = regex_constants::match_default); template basic_string regex_replace(const basic_string& s, const basic_regex& e, const charT* fmt,
regex_constants::match_flag_type flags = regex_constants::match_default); template basic_string regex_replace(const charT* s, const basic_regex& e, const basic_string& fmt,
regex_constants::match_flag_type flags = regex_constants::match_default); template basic_string regex_replace(const charT* s, const basic_regex& e, const charT* fmt,
regex_constants::match_flag_type flags = regex_constants::match_default); // [[re.regiter]](#regiter "28.6.11.1 Class template regex_iterator"), class template regex_iteratortemplate::value_type, class traits = regex_traits>class regex_iterator; using cregex_iterator = regex_iterator; using wcregex_iterator = regex_iterator; using sregex_iterator = regex_iterator; using wsregex_iterator = regex_iterator; // [[re.tokiter]](#tokiter "28.6.11.2 Class template regex_token_iterator"), class template regex_token_iteratortemplate::value_type, class traits = regex_traits>class regex_token_iterator; using cregex_token_iterator = regex_token_iterator; using wcregex_token_iterator = regex_token_iterator; using sregex_token_iterator = regex_token_iterator; using wsregex_token_iterator = regex_token_iterator; namespace pmr {templateusing match_results = std::match_results>>; using cmatch = match_results; using wcmatch = match_results; using smatch = match_results; using wsmatch = match_results; }}
### [28.6.4](#const) Namespace std::regex_constants [[re.const]](re.const)
#### [28.6.4.1](#const.general) General [[re.const.general]](re.const.general)
[1](#const.general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9595)
The namespace std::regex_constants holds
symbolic constants used by the regular expression library[.](#const.general-1.sentence-1)
This
namespace provides three types, syntax_option_type,match_flag_type, and error_type, along with several
constants of these types[.](#const.general-1.sentence-2)
#### [28.6.4.2](#synopt) Bitmask type syntax_option_type [[re.synopt]](re.synopt)
[ð](#lib:syntax_option_type)
namespace std::regex_constants {using syntax_option_type = *T1*; inline constexpr syntax_option_type icase = *unspecified*; inline constexpr syntax_option_type nosubs = *unspecified*; inline constexpr syntax_option_type optimize = *unspecified*; inline constexpr syntax_option_type collate = *unspecified*; inline constexpr syntax_option_type ECMAScript = *unspecified*; inline constexpr syntax_option_type basic = *unspecified*; inline constexpr syntax_option_type extended = *unspecified*; inline constexpr syntax_option_type awk = *unspecified*; inline constexpr syntax_option_type grep = *unspecified*; inline constexpr syntax_option_type egrep = *unspecified*; inline constexpr syntax_option_type multiline = *unspecified*;}
[1](#synopt-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9623)
The type syntax_option_type is an implementation-defined bitmask
type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))[.](#synopt-1.sentence-1)
Setting its elements has the effects listed in
Table [118](#tab:re.synopt "Table 118: syntax_option_type effects")[.](#synopt-1.sentence-2)
A valid value of typesyntax_option_type shall have at most one of the grammar elementsECMAScript, basic, extended, awk, grep, egrep, set[.](#synopt-1.sentence-3)
If no grammar element is set, the default grammar is ECMAScript[.](#synopt-1.sentence-4)
Table [118](#tab:re.synopt) — syntax_option_type effects [[tab:re.synopt]](./tab:re.synopt)
| [ð](#tab:re.synopt-row-1)
**Element** | **Effect(s) if set** |
| --- | --- |
| [ð](#tab:re.synopt-row-2)
icase | Specifies that matching of regular expressions against a character container sequence shall be performed without regard to case[.](#tab:re.synopt-row-2-column-2-sentence-1) |
| [ð](#tab:re.synopt-row-3)
nosubs | Specifies that no sub-expressions shall be considered to be marked, so that when a regular expression is matched against a character container sequence, no sub-expression matches shall be stored in the supplied match_results object[.](#tab:re.synopt-row-3-column-2-sentence-1) |
| [ð](#tab:re.synopt-row-4)
optimize | Specifies that the regular expression engine should pay more attention to the speed with which regular expressions are matched, and less to the speed with which regular expression objects are constructed[.](#tab:re.synopt-row-4-column-2-sentence-1)
Otherwise it has no detectable effect on the program output[.](#tab:re.synopt-row-4-column-2-sentence-2) |
| [ð](#tab:re.synopt-row-5)
collate | Specifies that character ranges of the form "[a-b]" shall be locale sensitive[.](#tab:re.synopt-row-5-column-2-sentence-1) |
| [ð](#tab:re.synopt-row-6)
ECMAScript | Specifies that the grammar recognized by the regular expression engine shall be that used by ECMAScript in ECMA-262, as modified in [[re.grammar]](#grammar "28.6.12 Modified ECMAScript regular expression grammar")[.](#tab:re.synopt-row-6-column-2-sentence-1)
See also: ECMA-262 15.10 |
| [ð](#tab:re.synopt-row-7)
basic | Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX[.](#tab:re.synopt-row-7-column-2-sentence-1) See also: POSIX, Base Definitions and Headers, Section 9.3 |
| [ð](#tab:re.synopt-row-8)
extended | Specifies that the grammar recognized by the regular expression engine shall be that used by extended regular expressions in POSIX[.](#tab:re.synopt-row-8-column-2-sentence-1) See also: POSIX, Base Definitions and Headers, Section 9.4 |
| [ð](#tab:re.synopt-row-9)
awk | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility awk in POSIX[.](#tab:re.synopt-row-9-column-2-sentence-1) |
| [ð](#tab:re.synopt-row-10)
grep | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep in POSIX[.](#tab:re.synopt-row-10-column-2-sentence-1) |
| [ð](#tab:re.synopt-row-11)
egrep | Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep when given the -E option in POSIX[.](#tab:re.synopt-row-11-column-2-sentence-1) |
| [ð](#tab:re.synopt-row-12)
multiline | Specifies that ^ shall match the beginning of a line and $ shall match the end of a line, if the ECMAScript engine is selected[.](#tab:re.synopt-row-12-column-2-sentence-1) |
#### [28.6.4.3](#matchflag) Bitmask type match_flag_type [[re.matchflag]](re.matchflag)
[ð](#lib:match_flag_type)
namespace std::regex_constants {using match_flag_type = *T2*; inline constexpr match_flag_type match_default = {}; inline constexpr match_flag_type match_not_bol = *unspecified*; inline constexpr match_flag_type match_not_eol = *unspecified*; inline constexpr match_flag_type match_not_bow = *unspecified*; inline constexpr match_flag_type match_not_eow = *unspecified*; inline constexpr match_flag_type match_any = *unspecified*; inline constexpr match_flag_type match_not_null = *unspecified*; inline constexpr match_flag_type match_continuous = *unspecified*; inline constexpr match_flag_type match_prev_avail = *unspecified*; inline constexpr match_flag_type format_default = {}; inline constexpr match_flag_type format_sed = *unspecified*; inline constexpr match_flag_type format_no_copy = *unspecified*; inline constexpr match_flag_type format_first_only = *unspecified*;}
[1](#matchflag-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9764)
The type match_flag_type is animplementation-defined bitmask type ([[bitmask.types]](bitmask.types "16.3.3.3.3 Bitmask types"))[.](#matchflag-1.sentence-1)
The constants of that type, except for match_default andformat_default, are bitmask elements[.](#matchflag-1.sentence-2)
The match_default andformat_default constants are empty bitmasks[.](#matchflag-1.sentence-3)
Matching a regular expression against a sequence of characters
[first, last) proceeds according to the rules of the grammar specified for the regular
expression object, modified according to the effects listed in Table [119](#tab:re.matchflag "Table 119: regex_constants::match_flag_type effects") for
any bitmask elements set[.](#matchflag-1.sentence-4)
Table [119](#tab:re.matchflag) — regex_constants::match_flag_type effects [[tab:re.matchflag]](./tab:re.matchflag)
| [ð](#tab:re.matchflag-row-1)
**Element** | **Effect(s) if set** |
| --- | --- |
| [ð](#tab:re.matchflag-row-2)
match_not_bol | The first character in the sequence [first, last) shall be treated as though it is not at the beginning of a line, so the character `^` in the regular expression shall not match [first, first)[.](#tab:re.matchflag-row-2-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-3)
match_not_eol | The last character in the sequence [first, last) shall be treated as though it is not at the end of a line, so the character `"$"` in the regular expression shall not match [last, last)[.](#tab:re.matchflag-row-3-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-4)
match_not_bow | The expression `"\\b"` shall not match the sub-sequence [first, first)[.](#tab:re.matchflag-row-4-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-5)
match_not_eow | The expression `"\\b"` shall not match the sub-sequence [last, last)[.](#tab:re.matchflag-row-5-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-6)
match_any | If more than one match is possible then any match is an acceptable result[.](#tab:re.matchflag-row-6-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-7)
match_not_null | The expression shall not match an empty sequence[.](#tab:re.matchflag-row-7-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-8)
match_continuous | The expression shall only match a sub-sequence that begins at first[.](#tab:re.matchflag-row-8-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-9)
match_prev_avail | `--first` is a valid iterator position[.](#tab:re.matchflag-row-9-column-2-sentence-1)
When this flag is set the flags match_not_bol and match_not_bow shall be ignored by the regular expression algorithms ([[re.alg]](#alg "28.6.10 Regular expression algorithms")) and iterators ([[re.iter]](#iter "28.6.11 Regular expression iterators"))[.](#tab:re.matchflag-row-9-column-2-sentence-2) |
| [ð](#tab:re.matchflag-row-10)
format_default | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the ECMAScript replace function in ECMA-262, part 15.5.4.11 String.prototype.replace[.](#tab:re.matchflag-row-10-column-2-sentence-1)
In addition, during search and replace operations all non-overlapping occurrences of the regular expression shall be located and replaced, and sections of the input that did not match the expression shall be copied unchanged to the output string[.](#tab:re.matchflag-row-10-column-2-sentence-2) |
| [ð](#tab:re.matchflag-row-11)
format_sed | When a regular expression match is to be replaced by a new string, the new string shall be constructed using the rules used by the sed utility in POSIX[.](#tab:re.matchflag-row-11-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-12)
format_no_copy | During a search and replace operation, sections of the character container sequence being searched that do not match the regular expression shall not be copied to the output string[.](#tab:re.matchflag-row-12-column-2-sentence-1) |
| [ð](#tab:re.matchflag-row-13)
format_first_only | When specified during a search and replace operation, only the first occurrence of the regular expression shall be replaced[.](#tab:re.matchflag-row-13-column-2-sentence-1) |
#### [28.6.4.4](#err) Implementation-defined error_type [[re.err]](re.err)
[ð](#lib:error_type)
namespace std::regex_constants {using error_type = *T3*; inline constexpr error_type error_collate = *unspecified*; inline constexpr error_type error_ctype = *unspecified*; inline constexpr error_type error_escape = *unspecified*; inline constexpr error_type error_backref = *unspecified*; inline constexpr error_type error_brack = *unspecified*; inline constexpr error_type error_paren = *unspecified*; inline constexpr error_type error_brace = *unspecified*; inline constexpr error_type error_badbrace = *unspecified*; inline constexpr error_type error_range = *unspecified*; inline constexpr error_type error_space = *unspecified*; inline constexpr error_type error_badrepeat = *unspecified*; inline constexpr error_type error_complexity = *unspecified*; inline constexpr error_type error_stack = *unspecified*;}
[1](#err-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9885)
The type error_type is an implementation-defined enumerated type ([[enumerated.types]](enumerated.types "16.3.3.3.2 Enumerated types"))[.](#err-1.sentence-1)
Values of type error_type represent the error
conditions described in Table [120](#tab:re.err "Table 120: error_type values in the C locale"):
Table [120](#tab:re.err) — error_type values in the C locale [[tab:re.err]](./tab:re.err)
| [ð](#tab:re.err-row-1)
**Value** | **Error condition** |
| --- | --- |
| [ð](#tab:re.err-row-2)
error_collate | The expression contains an invalid collating element name[.](#tab:re.err-row-2-column-2-sentence-1) |
| [ð](#tab:re.err-row-3)
error_ctype | The expression contains an invalid character class name[.](#tab:re.err-row-3-column-2-sentence-1) |
| [ð](#tab:re.err-row-4)
error_escape | The expression contains an invalid escaped character, or a trailing escape[.](#tab:re.err-row-4-column-2-sentence-1) |
| [ð](#tab:re.err-row-5)
error_backref | The expression contains an invalid back reference[.](#tab:re.err-row-5-column-2-sentence-1) |
| [ð](#tab:re.err-row-6)
error_brack | The expression contains mismatched `[` and `]`[.](#tab:re.err-row-6-column-2-sentence-1) |
| [ð](#tab:re.err-row-7)
error_paren | The expression contains mismatched `(` and `)`[.](#tab:re.err-row-7-column-2-sentence-1) |
| [ð](#tab:re.err-row-8)
error_brace | The expression contains mismatched `{` and `}`[.](#tab:re.err-row-8-column-2-sentence-1) |
| [ð](#tab:re.err-row-9)
error_badbrace | The expression contains an invalid range in a `{}` expression[.](#tab:re.err-row-9-column-2-sentence-1) |
| [ð](#tab:re.err-row-10)
error_range | The expression contains an invalid character range, such as `[b-a]` in most encodings[.](#tab:re.err-row-10-column-2-sentence-1) |
| [ð](#tab:re.err-row-11)
error_space | There is insufficient memory to convert the expression into a finite state machine[.](#tab:re.err-row-11-column-2-sentence-1) |
| [ð](#tab:re.err-row-12)
error_badrepeat | One of `*?+{` is not preceded by a valid regular expression[.](#tab:re.err-row-12-column-2-sentence-1) |
| [ð](#tab:re.err-row-13)
error_complexity | The complexity of an attempted match against a regular expression exceeds a pre-set level[.](#tab:re.err-row-13-column-2-sentence-1) |
| [ð](#tab:re.err-row-14)
error_stack | There is insufficient memory to determine whether the regular expression matches the specified character sequence[.](#tab:re.err-row-14-column-2-sentence-1) |
### [28.6.5](#badexp) Class regex_error [[re.badexp]](re.badexp)
[ð](#lib:regex_error)
namespace std {class regex_error : public runtime_error {public:explicit regex_error(regex_constants::error_type ecode);
regex_constants::error_type code() const; };}
[1](#badexp-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9968)
The class regex_error defines the type of objects thrown as
exceptions to report errors from the regular expression library[.](#badexp-1.sentence-1)
[ð](#lib:regex_error,constructor)
`regex_error(regex_constants::error_type ecode);
`
[2](#badexp-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9978)
*Postconditions*: ecode == code()[.](#badexp-2.sentence-1)
[ð](#lib:error_type__)
`regex_constants::error_type code() const;
`
[3](#badexp-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L9990)
*Returns*: The error code that was passed to the constructor[.](#badexp-3.sentence-1)
### [28.6.6](#traits) Class template regex_traits [[re.traits]](re.traits)
[ð](#lib:regex_traits)
namespace std {templatestruct regex_traits {using char_type = charT; using string_type = basic_string; using locale_type = locale; using char_class_type = *bitmask_type*;
regex_traits(); static size_t length(const char_type* p);
charT translate(charT c) const;
charT translate_nocase(charT c) const; template string_type transform(ForwardIterator first, ForwardIterator last) const; template string_type transform_primary( ForwardIterator first, ForwardIterator last) const; template string_type lookup_collatename( ForwardIterator first, ForwardIterator last) const; template char_class_type lookup_classname( ForwardIterator first, ForwardIterator last, bool icase = false) const; bool isctype(charT c, char_class_type f) const; int value(charT ch, int radix) const;
locale_type imbue(locale_type l);
locale_type getloc() const; };}
[1](#traits-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10029)
The specializations regex_traits andregex_traits meet the
requirements for a regular expression traits class ([[re.req]](#req "28.6.2 Requirements"))[.](#traits-1.sentence-1)
[ð](#lib:regex_traits,char_class_type)
`using char_class_type = bitmask_type;
`
[2](#traits-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10042)
The type char_class_type is used to represent a character
classification and is capable of holding an implementation specific
set returned by lookup_classname[.](#traits-2.sentence-1)
[ð](#lib:length,regex_traits)
`static size_t length(const char_type* p);
`
[3](#traits-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10054)
*Returns*: char_traits::length(p)[.](#traits-3.sentence-1)
[ð](#lib:regex_traits,translate)
`charT translate(charT c) const;
`
[4](#traits-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10065)
*Returns*: c[.](#traits-4.sentence-1)
[ð](#lib:regex_traits,translate_nocase)
`charT translate_nocase(charT c) const;
`
[5](#traits-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10076)
*Returns*: use_facet>(getloc()).tolower(c)[.](#traits-5.sentence-1)
[ð](#lib:regex_traits,transform)
`template
string_type transform(ForwardIterator first, ForwardIterator last) const;
`
[6](#traits-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10088)
*Effects*: As if by:string_type str(first, last);return use_facet>( getloc()).transform(str.data(), str.data() + str.length());
[ð](#lib:regex_traits,transform_primary)
`template
string_type transform_primary(ForwardIterator first, ForwardIterator last) const;
`
[7](#traits-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10105)
*Effects*: Iftypeid(use_facet>(getloc())) == typeid(collate_byname) and the form of the sort key returned
by collate_byname::transform(first, last) is known and
can be converted into a primary sort key then returns that key,
otherwise returns an empty string[.](#traits-7.sentence-1)
[ð](#lib:regex_traits,lookup_collatename)
`template
string_type lookup_collatename(ForwardIterator first, ForwardIterator last) const;
`
[8](#traits-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10124)
*Returns*: A sequence of one or more characters that
represents the collating element consisting of the character
sequence designated by the iterator range [first, last)[.](#traits-8.sentence-1)
Returns an empty string if the character sequence is not a
valid collating element[.](#traits-8.sentence-2)
[ð](#lib:regex_traits,lookup_classname)
`template
char_class_type lookup_classname(
ForwardIterator first, ForwardIterator last, bool icase = false) const;
`
[9](#traits-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10141)
*Returns*: An unspecified value that represents
the character classification named by the character sequence
designated by the iterator range [first, last)[.](#traits-9.sentence-1)
If the parameter icase is true then the returned mask identifies the
character classification without regard to the case of the characters being
matched, otherwise it does honor the case of the characters being
matched[.](#traits-9.sentence-2)[238](#footnote-238 "For example, if the parameter icase is true then [[:lower:]] is the same as [[:alpha:]].")
The value
returned shall be independent of the case of the characters in
the character sequence[.](#traits-9.sentence-3)
If the name
is not recognized then returns char_class_type()[.](#traits-9.sentence-4)
[10](#traits-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10159)
*Remarks*: For regex_traits, at least the narrow character names
in Table [121](#tab:re.traits.classnames "Table 121: Character class names and corresponding ctype masks") shall be recognized[.](#traits-10.sentence-1)
For regex_traits, at least the wide character names
in Table [121](#tab:re.traits.classnames "Table 121: Character class names and corresponding ctype masks") shall be recognized[.](#traits-10.sentence-2)
[ð](#lib:regex_traits,isctype)
`bool isctype(charT c, char_class_type f) const;
`
[11](#traits-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10173)
*Effects*: Determines if the character c is a member of the character
classification represented by f[.](#traits-11.sentence-1)
[12](#traits-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10178)
*Returns*: Given the following function declaration:// for exposition onlytemplate ctype_base::mask convert(typename regex_traits::char_class_type f); that returns a value in which each ctype_base::mask value corresponding to
a value in f named in Table [121](#tab:re.traits.classnames "Table 121: Character class names and corresponding ctype masks") is set, then the
result is determined as if by:ctype_base::mask m = convert(f);const ctype& ct = use_facet>(getloc());if (ct.is(m, c)) {return true;} else if (c == ct.widen('_')) { charT w[1] = { ct.widen('w') };
char_class_type x = lookup_classname(w, w+1); return (f&x) == x;} else {return false;}
[*Example [1](#traits-example-1)*: regex_traits t;
string d("d");
string u("upper");
regex_traits::char_class_type f;
f = t.lookup_classname(d.begin(), d.end());
f |= t.lookup_classname(u.begin(), u.end());
ctype_base::mask m = convert(f); // m == ctype_base::digit | ctype_base::upper â *end example*]
[*Example [2](#traits-example-2)*: regex_traits t;
string w("w");
regex_traits::char_class_type f;
f = t.lookup_classname(w.begin(), w.end());
t.isctype('A', f); // returns true t.isctype('_', f); // returns true t.isctype(' ', f); // returns false â *end example*]
[ð](#lib:value,regex_traits)
`int value(charT ch, int radix) const;
`
[13](#traits-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10232)
*Preconditions*: The value of radix is 8, 10, or 16[.](#traits-13.sentence-1)
[14](#traits-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10236)
*Returns*: The value represented by the digit ch in baseradix if the character ch is a valid digit in baseradix; otherwise returns -1[.](#traits-14.sentence-1)
[ð](#lib:locale)
`locale_type imbue(locale_type loc);
`
[15](#traits-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10250)
*Effects*: Imbues *this with a copy of the
locale loc[.](#traits-15.sentence-1)
[*Note [1](#traits-note-1)*:
Calling imbue with a
different locale than the one currently in use invalidates all cached
data held by *this[.](#traits-15.sentence-2)
â *end note*]
[16](#traits-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10260)
*Postconditions*: getloc() == loc[.](#traits-16.sentence-1)
[17](#traits-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10264)
*Returns*: If no locale has been previously imbued then a copy of the
global locale in effect at the time of construction of *this,
otherwise a copy of the last argument passed to imbue[.](#traits-17.sentence-1)
[ð](#lib:locale_)
`locale_type getloc() const;
`
[18](#traits-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10278)
*Returns*: If no locale has been imbued then a copy of the global locale
in effect at the time of construction of *this, otherwise a copy of
the last argument passed to imbue[.](#traits-18.sentence-1)
Table [121](#tab:re.traits.classnames) — Character class names and corresponding ctype masks [[tab:re.traits.classnames]](./tab:re.traits.classnames)
| [ð](#tab:re.traits.classnames-row-1)
**Narrow character name** | **Wide character name** | **Corresponding ctype_base::mask value** |
| --- | --- | --- |
| [ð](#tab:re.traits.classnames-row-2)
"alnum" | L"alnum" | ctype_base::alnum |
| [ð](#tab:re.traits.classnames-row-3)
"alpha" | L"alpha" | ctype_base::alpha |
| [ð](#tab:re.traits.classnames-row-4)
"blank" | L"blank" | ctype_base::blank |
| [ð](#tab:re.traits.classnames-row-5)
"cntrl" | L"cntrl" | ctype_base::cntrl |
| [ð](#tab:re.traits.classnames-row-6)
"digit" | L"digit" | ctype_base::digit |
| [ð](#tab:re.traits.classnames-row-7)
"d" | L"d" | ctype_base::digit |
| [ð](#tab:re.traits.classnames-row-8)
"graph" | L"graph" | ctype_base::graph |
| [ð](#tab:re.traits.classnames-row-9)
"lower" | L"lower" | ctype_base::lower |
| [ð](#tab:re.traits.classnames-row-10)
"print" | L"print" | ctype_base::print |
| [ð](#tab:re.traits.classnames-row-11)
"punct" | L"punct" | ctype_base::punct |
| [ð](#tab:re.traits.classnames-row-12)
"space" | L"space" | ctype_base::space |
| [ð](#tab:re.traits.classnames-row-13)
"s" | L"s" | ctype_base::space |
| [ð](#tab:re.traits.classnames-row-14)
"upper" | L"upper" | ctype_base::upper |
| [ð](#tab:re.traits.classnames-row-15)
"w" | L"w" | ctype_base::alnum |
| [ð](#tab:re.traits.classnames-row-16)
"xdigit" | L"xdigit" | ctype_base::xdigit |
[238)](#footnote-238)[238)](#footnoteref-238)
For example, if the parameter icase is true then[[:lower:]] is the same as [[:alpha:]][.](#footnote-238.sentence-1)
### [28.6.7](#regex) Class template basic_regex [[re.regex]](re.regex)
#### [28.6.7.1](#regex.general) General [[re.regex.general]](re.regex.general)
[1](#regex.general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10310)
For a char-like type charT, specializations of class
template basic_regex represent regular expressions constructed
from character sequences of charT characters[.](#regex.general-1.sentence-1)
In the rest
of [[re.regex]](#regex "28.6.7 Class template basic_regex"), charT denotes a given char-like
type[.](#regex.general-1.sentence-2)
Storage for a regular expression is allocated and freed as
necessary by the member functions of class basic_regex[.](#regex.general-1.sentence-3)
[2](#regex.general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10318)
Objects of type specialization of basic_regex are responsible for
converting the sequence of charT objects to an internal
representation[.](#regex.general-2.sentence-1)
It is not specified what form this representation
takes, nor how it is accessed by algorithms that operate on regular
expressions[.](#regex.general-2.sentence-2)
[*Note [1](#regex.general-note-1)*:
Implementations will typically declare
some function templates as friends of basic_regex to achieve
this[.](#regex.general-2.sentence-3)
â *end note*]
[3](#regex.general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10330)
The functions described in [[re.regex]](#regex "28.6.7 Class template basic_regex") report errors by throwing
exceptions of type regex_error[.](#regex.general-3.sentence-1)
[ð](#lib:basic_regex__)
namespace std {template>class basic_regex {public:// typesusing value_type = charT; using traits_type = traits; using string_type = typename traits::string_type; using flag_type = regex_constants::syntax_option_type; using locale_type = typename traits::locale_type; // [[re.synopt]](#synopt "28.6.4.2 Bitmask type syntax_option_type"), constantsstatic constexpr flag_type icase = regex_constants::icase; static constexpr flag_type nosubs = regex_constants::nosubs; static constexpr flag_type optimize = regex_constants::optimize; static constexpr flag_type collate = regex_constants::collate; static constexpr flag_type ECMAScript = regex_constants::ECMAScript; static constexpr flag_type basic = regex_constants::basic; static constexpr flag_type extended = regex_constants::extended; static constexpr flag_type awk = regex_constants::awk; static constexpr flag_type grep = regex_constants::grep; static constexpr flag_type egrep = regex_constants::egrep; static constexpr flag_type multiline = regex_constants::multiline; // [[re.regex.construct]](#regex.construct "28.6.7.2 Constructors"), construct/copy/destroy basic_regex(); explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
basic_regex(const basic_regex&);
basic_regex(basic_regex&&) noexcept; templateexplicit basic_regex(const basic_string& s,
flag_type f = regex_constants::ECMAScript); template basic_regex(ForwardIterator first, ForwardIterator last,
flag_type f = regex_constants::ECMAScript);
basic_regex(initializer_list il, flag_type f = regex_constants::ECMAScript); ~basic_regex(); // [[re.regex.assign]](#regex.assign "28.6.7.3 Assignment"), assign basic_regex& operator=(const basic_regex& e);
basic_regex& operator=(basic_regex&& e) noexcept;
basic_regex& operator=(const charT* p);
basic_regex& operator=(initializer_list il); template basic_regex& operator=(const basic_string& s);
basic_regex& assign(const basic_regex& e);
basic_regex& assign(basic_regex&& e) noexcept;
basic_regex& assign(const charT* p, flag_type f = regex_constants::ECMAScript);
basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript); template basic_regex& assign(const basic_string& s,
flag_type f = regex_constants::ECMAScript); template basic_regex& assign(InputIterator first, InputIterator last,
flag_type f = regex_constants::ECMAScript);
basic_regex& assign(initializer_list,
flag_type f = regex_constants::ECMAScript); // [[re.regex.operations]](#regex.operations "28.6.7.4 Constant operations"), const operationsunsigned mark_count() const;
flag_type flags() const; // [[re.regex.locale]](#regex.locale "28.6.7.5 Locale"), locale locale_type imbue(locale_type loc);
locale_type getloc() const; // [[re.regex.swap]](#regex.swap "28.6.7.6 Swap"), swapvoid swap(basic_regex&); }; template basic_regex(ForwardIterator, ForwardIterator,
regex_constants::syntax_option_type = regex_constants::ECMAScript)-> basic_regex::value_type>;}
#### [28.6.7.2](#regex.construct) Constructors [[re.regex.construct]](re.regex.construct)
[ð](#lib:basic_regex,constructor)
`basic_regex();
`
[1](#regex.construct-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10425)
*Postconditions*: *this does not match any character sequence[.](#regex.construct-1.sentence-1)
[ð](#lib:basic_regex,constructor_)
`explicit basic_regex(const charT* p, flag_type f = regex_constants::ECMAScript);
`
[2](#regex.construct-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10436)
*Preconditions*: [p, p + char_traits::length(p)) is a valid range[.](#regex.construct-2.sentence-1)
[3](#regex.construct-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10440)
*Effects*: The object's internal finite state machine
is constructed from the regular expression contained in
the sequence of characters
[p, p + char_traits::length(p)), and
interpreted according to the flags f[.](#regex.construct-3.sentence-1)
[4](#regex.construct-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10448)
*Postconditions*: flags() returns f[.](#regex.construct-4.sentence-1)
mark_count() returns the number of marked sub-expressions
within the expression[.](#regex.construct-4.sentence-2)
[5](#regex.construct-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10454)
*Throws*: regex_error if
[p, p + char_traits::length(p)) is not a valid regular expression[.](#regex.construct-5.sentence-1)
[ð](#lib:basic_regex,constructor__)
`basic_regex(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
`
[6](#regex.construct-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10466)
*Preconditions*: [p, p + len) is a valid range[.](#regex.construct-6.sentence-1)
[7](#regex.construct-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10470)
*Effects*: The object's internal finite state machine
is constructed from the regular expression contained in
the sequence of characters [p, p + len), and
interpreted according the flags specified in f[.](#regex.construct-7.sentence-1)
[8](#regex.construct-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10477)
*Postconditions*: flags() returns f[.](#regex.construct-8.sentence-1)
mark_count() returns the number of marked sub-expressions
within the expression[.](#regex.construct-8.sentence-2)
[9](#regex.construct-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10483)
*Throws*: regex_error if [p, p + len) is not a valid regular expression[.](#regex.construct-9.sentence-1)
[ð](#lib:basic_regex,constructor___)
`basic_regex(const basic_regex& e);
`
[10](#regex.construct-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10494)
*Postconditions*: flags() and mark_count() returne.flags() and e.mark_count(), respectively[.](#regex.construct-10.sentence-1)
[ð](#lib:basic_regex,constructor____)
`basic_regex(basic_regex&& e) noexcept;
`
[11](#regex.construct-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10506)
*Postconditions*: flags() and mark_count() return the values thate.flags() and e.mark_count(), respectively, had before construction[.](#regex.construct-11.sentence-1)
[ð](#lib:basic_regex,constructor_____)
`template
explicit basic_regex(const basic_string& s,
flag_type f = regex_constants::ECMAScript);
`
[12](#regex.construct-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10520)
*Effects*: The object's internal finite state machine
is constructed from the regular expression contained in
the string s, and
interpreted according to the flags specified in f[.](#regex.construct-12.sentence-1)
[13](#regex.construct-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10527)
*Postconditions*: flags() returns f[.](#regex.construct-13.sentence-1)
mark_count() returns the number of marked sub-expressions
within the expression[.](#regex.construct-13.sentence-2)
[14](#regex.construct-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10533)
*Throws*: regex_error if s is not a valid regular expression[.](#regex.construct-14.sentence-1)
[ð](#lib:basic_regex,constructor______)
`template
basic_regex(ForwardIterator first, ForwardIterator last,
flag_type f = regex_constants::ECMAScript);
`
[15](#regex.construct-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10546)
*Effects*: The object's internal finite state machine
is constructed from the regular expression contained in
the sequence of characters [first, last), and
interpreted according to the flags specified in f[.](#regex.construct-15.sentence-1)
[16](#regex.construct-16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10553)
*Postconditions*: flags() returns f[.](#regex.construct-16.sentence-1)
mark_count() returns the number of marked sub-expressions
within the expression[.](#regex.construct-16.sentence-2)
[17](#regex.construct-17)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10559)
*Throws*: regex_error if the sequence [first, last) is not a
valid regular expression[.](#regex.construct-17.sentence-1)
[ð](#lib:basic_regex,constructor_______)
`basic_regex(initializer_list il, flag_type f = regex_constants::ECMAScript);
`
[18](#regex.construct-18)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10571)
*Effects*: Same as basic_regex(il.begin(), il.end(), f)[.](#regex.construct-18.sentence-1)
#### [28.6.7.3](#regex.assign) Assignment [[re.regex.assign]](re.regex.assign)
[ð](#lib:basic_regex,operator=)
`basic_regex& operator=(const basic_regex& e);
`
[1](#regex.assign-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10584)
*Postconditions*: flags() and mark_count() returne.flags() and e.mark_count(), respectively[.](#regex.assign-1.sentence-1)
[ð](#lib:basic_regex,operator=_)
`basic_regex& operator=(basic_regex&& e) noexcept;
`
[2](#regex.assign-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10596)
*Postconditions*: flags() and mark_count() return the values thate.flags() and e.mark_count(), respectively, had before assignment[.](#regex.assign-2.sentence-1)
e is in a valid state with unspecified value[.](#regex.assign-2.sentence-2)
[ð](#lib:basic_regex,operator=__)
`basic_regex& operator=(const charT* p);
`
[3](#regex.assign-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10609)
*Effects*: Equivalent to: return assign(p);
[ð](#lib:basic_regex,operator=___)
`basic_regex& operator=(initializer_list il);
`
[4](#regex.assign-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10620)
*Effects*: Equivalent to: return assign(il.begin(), il.end());
[ð](#lib:basic_regex,operator=____)
`template
basic_regex& operator=(const basic_string& s);
`
[5](#regex.assign-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10632)
*Effects*: Equivalent to: return assign(s);
[ð](#lib:basic_regex,assign)
`basic_regex& assign(const basic_regex& e);
`
[6](#regex.assign-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10643)
*Effects*: Equivalent to: return *this = e;
[ð](#lib:basic_regex,assign_)
`basic_regex& assign(basic_regex&& e) noexcept;
`
[7](#regex.assign-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10654)
*Effects*: Equivalent to: return *this = std::move(e);
[ð](#lib:basic_regex,assign__)
`basic_regex& assign(const charT* p, flag_type f = regex_constants::ECMAScript);
`
[8](#regex.assign-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10665)
*Effects*: Equivalent to: return assign(string_type(p), f);
[ð](#lib:basic_regex,assign___)
`basic_regex& assign(const charT* p, size_t len, flag_type f = regex_constants::ECMAScript);
`
[9](#regex.assign-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10676)
*Effects*: Equivalent to: return assign(string_type(p, len), f);
[ð](#lib:basic_regex,assign____)
`template
basic_regex& assign(const basic_string& s,
flag_type f = regex_constants::ECMAScript);
`
[10](#regex.assign-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10689)
*Effects*: Assigns the regular expression contained in the strings, interpreted according the flags specified in f[.](#regex.assign-10.sentence-1)
If an exception is thrown, *this is unchanged[.](#regex.assign-10.sentence-2)
[11](#regex.assign-11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10695)
*Postconditions*: If no exception is thrown,flags() returns f and mark_count() returns the number of marked sub-expressions within the expression[.](#regex.assign-11.sentence-1)
[12](#regex.assign-12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10701)
*Returns*: *this[.](#regex.assign-12.sentence-1)
[13](#regex.assign-13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10705)
*Throws*: regex_error if s is not a valid regular expression[.](#regex.assign-13.sentence-1)
[ð](#lib:basic_regex,assign_____)
`template
basic_regex& assign(InputIterator first, InputIterator last,
flag_type f = regex_constants::ECMAScript);
`
[14](#regex.assign-14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10718)
*Effects*: Equivalent to: return assign(string_type(first, last), f);
[ð](#lib:assign,basic_regex______)
`basic_regex& assign(initializer_list il,
flag_type f = regex_constants::ECMAScript);
`
[15](#regex.assign-15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10730)
*Effects*: Equivalent to: return assign(il.begin(), il.end(), f);
#### [28.6.7.4](#regex.operations) Constant operations [[re.regex.operations]](re.regex.operations)
[ð](#lib:mark_count,basic_regex)
`unsigned mark_count() const;
`
[1](#regex.operations-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10744)
*Effects*: Returns the number of marked sub-expressions within the
regular expression[.](#regex.operations-1.sentence-1)
[ð](#lib:flag_type,basic_regex)
`flag_type flags() const;
`
[2](#regex.operations-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10756)
*Effects*: Returns a copy of the regular expression syntax flags that
were passed to the object's constructor or to the last call
to assign[.](#regex.operations-2.sentence-1)
#### [28.6.7.5](#regex.locale) Locale [[re.regex.locale]](re.regex.locale)
[ð](#lib:imbue,basic_regex)
`locale_type imbue(locale_type loc);
`
[1](#regex.locale-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10772)
*Effects*: Returns the result of traits_inst.imbue(loc) wheretraits_inst is a (default-initialized) instance of the template
type argument traits stored within the object[.](#regex.locale-1.sentence-1)
After a call
to imbue the basic_regex object does not match any
character sequence[.](#regex.locale-1.sentence-2)
[ð](#lib:getloc,basic_regex)
`locale_type getloc() const;
`
[2](#regex.locale-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10787)
*Effects*: Returns the result of traits_inst.getloc() wheretraits_inst is a (default-initialized) instance of the template
parameter traits stored within the object[.](#regex.locale-2.sentence-1)
#### [28.6.7.6](#regex.swap) Swap [[re.regex.swap]](re.regex.swap)
[ð](#lib:swap,basic_regex_)
`void swap(basic_regex& e);
`
[1](#regex.swap-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10803)
*Effects*: Swaps the contents of the two regular expressions[.](#regex.swap-1.sentence-1)
[2](#regex.swap-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10807)
*Postconditions*: *this contains the regular expression
that was in e, e contains the regular expression that
was in *this[.](#regex.swap-2.sentence-1)
[3](#regex.swap-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10813)
*Complexity*: Constant time[.](#regex.swap-3.sentence-1)
#### [28.6.7.7](#regex.nonmemb) Non-member functions [[re.regex.nonmemb]](re.regex.nonmemb)
[ð](#lib:basic_regex,swap__)
`template
void swap(basic_regex& lhs, basic_regex& rhs);
`
[1](#regex.nonmemb-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10827)
*Effects*: Calls lhs.swap(rhs)[.](#regex.nonmemb-1.sentence-1)
### [28.6.8](#submatch) Class template sub_match [[re.submatch]](re.submatch)
#### [28.6.8.1](#submatch.general) General [[re.submatch.general]](re.submatch.general)
[1](#submatch.general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10835)
Class template sub_match denotes the sequence of characters matched
by a particular marked sub-expression[.](#submatch.general-1.sentence-1)
namespace std {templateclass sub_match : public pair {public:using value_type =typename iterator_traits::value_type; using difference_type =typename iterator_traits::difference_type; using iterator = BidirectionalIterator; using string_type = basic_string; bool matched; constexpr sub_match();
difference_type length() const; operator string_type() const;
string_type str() const; int compare(const sub_match& s) const; int compare(const string_type& s) const; int compare(const value_type* s) const; void swap(sub_match& s) noexcept(*see below*); };}
#### [28.6.8.2](#submatch.members) Members [[re.submatch.members]](re.submatch.members)
[ð](#lib:sub_match,constructor)
`constexpr sub_match();
`
[1](#submatch.members-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10878)
*Effects*: Value-initializes the pair base class subobject and the membermatched[.](#submatch.members-1.sentence-1)
[ð](#lib:sub_match,length)
`difference_type length() const;
`
[2](#submatch.members-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10890)
*Returns*: matched ? distance(first, second) : 0[.](#submatch.members-2.sentence-1)
[ð](#lib:operator_basic_string,sub_match)
`operator string_type() const;
`
[3](#submatch.members-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10901)
*Returns*: matched ? string_type(first, second) : string_type()[.](#submatch.members-3.sentence-1)
[ð](#lib:sub_match,str)
`string_type str() const;
`
[4](#submatch.members-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10912)
*Returns*: matched ? string_type(first, second) : string_type()[.](#submatch.members-4.sentence-1)
[ð](#lib:sub_match,compare)
`int compare(const sub_match& s) const;
`
[5](#submatch.members-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10923)
*Returns*: str().compare(s.str())[.](#submatch.members-5.sentence-1)
[ð](#lib:sub_match,compare_)
`int compare(const string_type& s) const;
`
[6](#submatch.members-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10934)
*Returns*: str().compare(s)[.](#submatch.members-6.sentence-1)
[ð](#lib:sub_match,compare__)
`int compare(const value_type* s) const;
`
[7](#submatch.members-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10945)
*Returns*: str().compare(s)[.](#submatch.members-7.sentence-1)
[ð](#lib:sub_match,swap)
`void swap(sub_match& s) noexcept(see below);
`
[8](#submatch.members-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10956)
*Preconditions*: BidirectionalIterator meets
the *Cpp17Swappable* requirements ([[swappable.requirements]](swappable.requirements "16.4.4.3 Swappable requirements"))[.](#submatch.members-8.sentence-1)
[9](#submatch.members-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10961)
*Effects*: Equivalent to:this->pair::swap(s);
std::swap(matched, s.matched);
[10](#submatch.members-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10969)
*Remarks*: The exception specification is equivalent tois_nothrow_swappable_v[.](#submatch.members-10.sentence-1)
#### [28.6.8.3](#submatch.op) Non-member operators [[re.submatch.op]](re.submatch.op)
[1](#submatch.op-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10977)
Let *SM-CAT*(I) becompare_three_way_result_t::value_type>>
[ð](#lib:sub_match,operator==)
`template
bool operator==(const sub_match& lhs, const sub_match& rhs);
`
[2](#submatch.op-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L10990)
*Returns*: lhs.compare(rhs) == 0[.](#submatch.op-2.sentence-1)
[ð](#lib:sub_match,operator%3c=%3e)
`template
auto operator<=>(const sub_match& lhs, const sub_match& rhs);
`
[3](#submatch.op-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11002)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(rhs) <=> 0)[.](#submatch.op-3.sentence-1)
[ð](#lib:operator==,sub_match_)
`template
bool operator==(
const sub_match& lhs,
const basic_string::value_type, ST, SA>& rhs);
`
[4](#submatch.op-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11016)
*Returns*: lhs.compare(typename sub_match::string_type(rhs.data(), rhs.size())) == 0
[ð](#lib:operator%3c=%3e,sub_match_)
`template
auto operator<=>(
const sub_match& lhs,
const basic_string::value_type, ST, SA>& rhs);
`
[5](#submatch.op-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11032)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(typename sub_match::string_type(rhs.data(), rhs.size()))<=> 0)
[ð](#lib:sub_match,operator==__)
`template
bool operator==(const sub_match& lhs,
const typename iterator_traits::value_type* rhs);
`
[6](#submatch.op-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11050)
*Returns*: lhs.compare(rhs) == 0[.](#submatch.op-6.sentence-1)
[ð](#lib:sub_match,operator%3c=%3e__)
`template
auto operator<=>(const sub_match& lhs,
const typename iterator_traits::value_type* rhs);
`
[7](#submatch.op-7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11063)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(rhs) <=> 0)[.](#submatch.op-7.sentence-1)
[ð](#lib:sub_match,operator==___)
`template
bool operator==(const sub_match& lhs,
const typename iterator_traits::value_type& rhs);
`
[8](#submatch.op-8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11076)
*Returns*: lhs.compare(typename sub_match::string_type(1, rhs)) == 0[.](#submatch.op-8.sentence-1)
[ð](#lib:sub_match,operator%3c=%3e___)
`template
auto operator<=>(const sub_match& lhs,
const typename iterator_traits::value_type& rhs);
`
[9](#submatch.op-9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11089)
*Returns*: static_cast<*SM-CAT*(BiIter)>(lhs.compare(typename sub_match::string_type(1, rhs))<=> 0)
[ð](#lib:basic_ostream)
`template
basic_ostream&
operator<<(basic_ostream& os, const sub_match& m);
`
[10](#submatch.op-10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11108)
*Returns*: os << m.str()[.](#submatch.op-10.sentence-1)
### [28.6.9](#results) Class template match_results [[re.results]](re.results)
#### [28.6.9.1](#results.general) General [[re.results.general]](re.results.general)
[1](#results.general-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11116)
Class template match_results denotes a collection of character
sequences representing the result of a regular expression
match[.](#results.general-1.sentence-1)
Storage for the collection is allocated and freed as necessary
by the member functions of class template match_results[.](#results.general-1.sentence-2)
[2](#results.general-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11123)
The class template match_results meets the requirements of an
allocator-aware container ([[container.alloc.reqmts]](container.alloc.reqmts "23.2.2.5 Allocator-aware containers")) and of
a sequence container ([[container.requirements.general]](container.requirements.general "23.2.2 General containers"), [[sequence.reqmts]](sequence.reqmts "23.2.4 Sequence containers"))
except that only
copy assignment,
move assignment, and
operations defined for const-qualified sequence containers
are supported and
that the semantics of the comparison operator functions are different from those
required for a container[.](#results.general-2.sentence-1)
[3](#results.general-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11137)
A default-constructed match_results object has no fully established result state[.](#results.general-3.sentence-1)
A
match result is [*ready*](futures.state#def:ready "32.10.5 Shared state [futures.state]") when, as a consequence of a completed regular expression match
modifying such an object, its result state becomes fully established[.](#results.general-3.sentence-2)
The effects of calling
most member functions from a match_results object that is not ready are undefined[.](#results.general-3.sentence-3)
[4](#results.general-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/text.tex#L11143)
The sub_match object stored at index 0 represents sub-expression 0,
i.e., the whole match[.](#results.general-4.sentence-1)
In this case the sub_match membermatched is always true[.](#results.general-4.sentence-2)
The sub_match object stored at index n denotes what matched the marked
sub-expression n within the matched expression[.](#results.general-4.sentence-3)
If the
sub-expression n participated in a regular expression
match then the sub_match member matched evaluates to true, and
members first and second denote the range of characters
[first, second) which formed that
match[.](#results.general-4.sentence-4)
Otherwise matched is false, and members first and second point to the end of the sequence
that was searched[.](#results.general-4.sentence-5)
[*Note [1](#results.general-note-1)*:
The sub_match objects representing
different sub-expressions that did not participate in a regular expression
match need not be distinct[.](#results.general-4.sentence-6)
â *end note*]
namespace std {template>>class match_results {public:using value_type = sub_match; using const_reference = const value_type&; using reference = value_type&; using const_iterator = *implementation-defined*; using iterator = const_iterator; using difference_type =typename iterator_traits::difference_type; using size_type = typename allocator_traits::size_type; using allocator_type = Allocator; using char_type =typename iterator_traits::value_type; using string_type = basic_string; // [[re.results.const]](#results.const "28.6.9.2 Constructors"), construct/copy/destroy match_results() : match_results(Allocator()) {}explicit match_results(const Allocator& a);
match_results(const match_results& m);
match_results(const match_results& m, const Allocator& a);
match_results(match_results&& m) noexcept;
match_results(match_results&& m, const Allocator& a);
match_results& operator=(const match_results& m);
match_results& operator=(match_results&& m); ~match_results(); // [[re.results.state]](#results.state "28.6.9.3 State"), statebool ready() const; // [[re.results.size]](#results.size "28.6.9.4 Size"), size size_type size() const;
size_type max_size() const; bool empty() const; // [[re.results.acc]](#results.acc "28.6.9.5 Element access"), element access difference_type length(size_type sub = 0) const;
difference_type position(size_type sub = 0) const;
string_type str(size_type sub = 0) const;
const_reference operator[](size_type n) const;
const_reference prefix() const;
const_reference suffix() const;
const_iterator begin() const;
const_iterator end() const;
const_iterator cbegin() const;
const_iterator cend() const; // [[re.results.form]](#results.form "28.6.9.6 Formatting"), formattemplate OutputIter
format(OutputIter out, const char_type* fmt_first, const char_type* fmt_last,
regex_constants::match_flag_type flags = regex_constants::format_default) const; template OutputIter
format(OutputIter out, const basic_string& fmt,
regex_constants::match_flag_type flags = regex_constants::format_default) const; template basic_string format(const basic_string