std::regex_constants(3cxx)
π NAME π
std::regex_constants β okay so this is the ISO C++ 2011 namespace for all the options and flags you use with std::regex. The whole namespace, bestie. It lives in the 3cxx manual and it's lowkey iconic. β¨
β¨ SYNOPSIS β¨
π 5.1 Regular Expression Syntax Options
enum syntax_option_type : unsigned int { _S_icase, _S_nosubs,
_S_optimize, _S_collate, _S_ECMAScript, _S_basic, _S_extended,
_S_awk, _S_grep, _S_egrep, _S_polynomial, _S_multiline }
This is a bitmask type indicating how to interpret the regex. periodt. π
And here's the whole constexpr squad, verbatim:
constexpr syntax_option_type icase
constexpr syntax_option_type nosubs
constexpr syntax_option_type optimize
constexpr syntax_option_type collate
constexpr syntax_option_type ECMAScript
constexpr syntax_option_type basic
constexpr syntax_option_type extended
constexpr syntax_option_type awk
constexpr syntax_option_type grep
constexpr syntax_option_type egrep
constexpr syntax_option_type multiline
__multilineβ extension alert π¦ it's equivalent toregex_constants::multilinefor C++11 and C++14. So:constexpr syntax_option_type __multiline.__polynomialβ yep, it's in the list too:constexpr syntax_option_type __polynomial. That's all the page gives us, no cap.
Now the operators, all noexcept, all doing that bitmask thing. π«
operator&βconstexpr syntax_option_type operator& (syntax_option_type __a, syntax_option_type __b) noexcept. This is a bitmask type indicating how to interpret the regex.operator|βconstexpr syntax_option_type operator| (syntax_option_type __a, syntax_option_type __b) noexcept. This is a bitmask type indicating how to interpret the regex.operator^βconstexpr syntax_option_type operator^ (syntax_option_type __a, syntax_option_type __b) noexcept. This is a bitmask type indicating how to interpret the regex.operator~βconstexpr syntax_option_type operator~ (syntax_option_type __a) noexcept. This is a bitmask type indicating how to interpret the regex.operator&=βconstexpr syntax_option_type & operator&= (syntax_option_type &__a, syntax_option_type __b) noexcept. This is a bitmask type indicating how to interpret the regex.operator|=βconstexpr syntax_option_type & operator|= (syntax_option_type &__a, syntax_option_type __b) noexcept. This is a bitmask type indicating how to interpret the regex.operator^=βconstexpr syntax_option_type & operator^= (syntax_option_type &__a, syntax_option_type __b) noexcept. This is a bitmask type indicating how to interpret the regex.
πΈ 5.2 Matching Rules
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 below for any bitmask elements set. iykyk π«Ά
enum match_flag_type : unsigned int { _S_default, _S_not_bol,
_S_not_eol, _S_not_bow, _S_not_eow, _S_any, _S_not_null,
_S_continuous, _S_prev_avail, _S_sed, _S_no_copy, _S_first_only,
_S_match_flag_last }
This is a bitmask type indicating regex matching rules. π
The constexpr crew:
constexpr match_flag_type match_default
constexpr match_flag_type match_not_bol
constexpr match_flag_type match_not_eol
constexpr match_flag_type match_not_bow
constexpr match_flag_type match_not_eow
constexpr match_flag_type match_any
constexpr match_flag_type match_not_null
constexpr match_flag_type match_continuous
constexpr match_flag_type match_prev_avail
constexpr match_flag_type format_default
constexpr match_flag_type format_sed
constexpr match_flag_type format_no_copy
constexpr match_flag_type format_first_only
And the operator lineup for this bitmask type, all noexcept: π
operator&βconstexpr match_flag_type operator& (match_flag_type __a, match_flag_type __b) noexcept. This is a bitmask type indicating regex matching rules.operator|βconstexpr match_flag_type operator| (match_flag_type __a, match_flag_type __b) noexcept. This is a bitmask type indicating regex matching rules.operator^βconstexpr match_flag_type operator^ (match_flag_type __a, match_flag_type __b) noexcept. This is a bitmask type indicating regex matching rules.operator~βconstexpr match_flag_type operator~ (match_flag_type __a) noexcept. This is a bitmask type indicating regex matching rules.operator&=βconstexpr match_flag_type & operator&= (match_flag_type &__a, match_flag_type __b) noexcept. This is a bitmask type indicating regex matching rules.operator|=βconstexpr match_flag_type & operator|= (match_flag_type &__a, match_flag_type __b) noexcept. This is a bitmask type indicating regex matching rules.operator^=βconstexpr match_flag_type & operator^= (match_flag_type &__a, match_flag_type __b) noexcept. This is a bitmask type indicating regex matching rules.
π¦ 5.3 Error Types
enum error_type { _S_error_collate, _S_error_ctype, _S_error_escape,
_S_error_backref, _S_error_brack, _S_error_paren, _S_error_brace,
_S_error_badbrace, _S_error_range, _S_error_space,
_S_error_badrepeat, _S_error_complexity, _S_error_stack, _S_null,
_S_grammar }
These are literally defined as constexpr values wrapping the internals, so here they are, exactly, no notes: π
constexpr error_type error_collate (_S_error_collate)
constexpr error_type error_ctype (_S_error_ctype)
constexpr error_type error_escape (_S_error_escape)
constexpr error_type error_backref (_S_error_backref)
constexpr error_type error_brack (_S_error_brack)
constexpr error_type error_paren (_S_error_paren)
constexpr error_type error_brace (_S_error_brace)
constexpr error_type error_badbrace (_S_error_badbrace)
constexpr error_type error_range (_S_error_range)
constexpr error_type error_space (_S_error_space)
constexpr error_type error_badrepeat (_S_error_badrepeat)
constexpr error_type error_complexity (_S_error_complexity)
constexpr error_type error_stack (_S_error_stack)
π Detailed Description π
ISO C++ 2011 namespace for options and flags used with std::regex. That's the whole vibe check and honestly it ate. π
β Enumeration Type Documentation β
π enum std::regex_constants::error_type
The expression contained an invalid collating element name. Yep, that's what it says, fr fr.
π₯ enum std::regex_constants::match_flag_type : unsigned int
This is a bitmask type indicating regex matching rules. The match_flag_type is implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. So bitwise away, bestie, it'll behave. β¨
π§ enum std::regex_constants::syntax_option_type : unsigned int
This is a bitmask type indicating how to interpret the regex. The syntax_option_type is implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. π«
Heads up, this one's important: a valid value of typesyntax_option_typeshall have exactly one of the elementsECMAScript,basic,extended,awk,grep,egrepset. Exactly one. Not zero, not two. Main character energy only. π
β¨ FUNCTION DOCUMENTATION β¨
okay bestie, buckle up π this is the part where every single one of these little constexpr gremlins gets its own moment in the sun. They're all inline, they're all constexpr, and they're all here to help you figure out exactly why your regex just betrayed you π
πΈ The error_type royal family πΈ
Every one of these bad boys is a constexpr error_type β think of them as the receipts your regex engine hands you when the vibes are off. Signature first, then the tea π
constexpr error_type std::regex_constants::error_backref(_S_error_backref)β [inline], [constexpr] β the expression contained an invalid back reference. like, you pointed at a group that isn't there. ghosting, but make it regex πconstexpr error_type std::regex_constants::error_badbrace(_S_error_badbrace)β [inline], [constexpr] β the expression contained an invalid range in a{}expression. the curly braces said "not today" πconstexpr error_type std::regex_constants::error_badrepeat(_S_error_badrepeat)β [inline], [constexpr] β one of*?+{was not preceded by a valid regular expression. you can't just repeat nothing, bestie, that's not how main character energy works β¨constexpr error_type std::regex_constants::error_brace(_S_error_brace)β [inline], [constexpr] β the expression contained mismatched{and}. one of them showed up to the party and the other one ghosted πconstexpr error_type std::regex_constants::error_brack(_S_error_brack)β [inline], [constexpr] β the expression contained mismatched[and]. same energy, different brackets π¦constexpr error_type std::regex_constants::error_collate(_S_error_collate)β [inline], [constexpr] β the expression contained an invalid collating element name. that collation name? not a real one. it's giving made-up β¨constexpr error_type std::regex_constants::error_complexity(_S_error_complexity)β [inline], [constexpr] β the complexity of an attempted match against a regular expression exceeded a pre-set level. your regex was simply too much to handle, and honestly? relatable π₯constexpr error_type std::regex_constants::error_ctype(_S_error_ctype)β [inline], [constexpr] β the expression contained an invalid character class name. that class name is not on the roster πconstexpr error_type std::regex_constants::error_escape(_S_error_escape)β [inline], [constexpr] β the expression contained an invalid escaped character, or a trailing escape. backslash said "and then what?" and nobody answered πconstexpr error_type std::regex_constants::error_paren(_S_error_paren)β [inline], [constexpr] β the expression contained mismatched(and). the parenthesis lore is not matching up π«Άconstexpr error_type std::regex_constants::error_range(_S_error_range)β [inline], [constexpr] β the expression contained an invalid character range, such as[b-a]in most encodings. backwards range, backwards vibes πconstexpr error_type std::regex_constants::error_space(_S_error_space)β [inline], [constexpr] β there was insufficient memory to convert the expression into a finite state machine. the machine ran out of room to be built. no cap πconstexpr error_type std::regex_constants::error_stack(_S_error_stack)β [inline], [constexpr] β there was insufficient memory to determine whether the regular expression could match the specified character sequence. it couldn't even check, the memory just wasn't there πΈ
π¦ The bitmask operators π¦
now the fun part, bestie β all the bitwise shenanigans π two families here: match_flag_type (which is all about regex matching rules) and syntax_option_type (which is all about how to interpret the regex). both are implementation defined, but the whole point is that bitwise operations on them are valid and you can expect the right thing to happen. periodt β¨
heads up π everysyntax_option_typeoperator below carries this exact caveat, so listen close: a valid value of typesyntax_option_typeshall have exactly one of the elementsECMAScript,basic,extended,awk,grep,egrepset. exactly one, bestie. not zero, not two. one π
AND-ing it up
constexpr match_flag_type std::regex_constants::operator&(match_flag_type __a, match_flag_type __b)β [constexpr], [noexcept] β this is a bitmask type indicating regex matching rules. thematch_flag_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen π«Άconstexpr syntax_option_type std::regex_constants::operator&(syntax_option_type __a, syntax_option_type __b)β [constexpr], [noexcept] β this is a bitmask type indicating how to interpret the regex. thesyntax_option_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. and remember: a valid value shall have exactly one ofECMAScript,basic,extended,awk,grep,egrepset πconstexpr match_flag_type &std::regex_constants::operator&=(match_flag_type &__a, match_flag_type __b)β [inline], [constexpr], [noexcept] β this is a bitmask type indicating regex matching rules. thematch_flag_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. now in place, slay πconstexpr syntax_option_type &std::regex_constants::operator&=(syntax_option_type &__a, syntax_option_type __b)β [inline], [constexpr], [noexcept] β this is a bitmask type indicating how to interpret the regex. thesyntax_option_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. plus the usual: a valid value of typesyntax_option_typeshall have exactly one ofECMAScript,basic,extended,awk,grep,egrepset π
XOR girlies
constexpr match_flag_type std::regex_constants::operator^(match_flag_type __a, match_flag_type __b)β [constexpr], [noexcept] β this is a bitmask type indicating regex matching rules. thematch_flag_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen π₯constexpr syntax_option_type std::regex_constants::operator^(syntax_option_type __a, syntax_option_type __b)β [constexpr], [noexcept] β this is a bitmask type indicating how to interpret the regex. thesyntax_option_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. and yeah: a valid value of typesyntax_option_typeshall have exactly one ofECMAScript,basic,extended,awk,grep,egrepset π¦constexpr match_flag_type &std::regex_constants::operator^=(match_flag_type &__a, match_flag_type __b)β [inline], [constexpr], [noexcept] β this is a bitmask type indicating regex matching rules. thematch_flag_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen β¨constexpr syntax_option_type &std::regex_constants::operator^=(syntax_option_type &__a, syntax_option_type __b)β [inline], [constexpr], [noexcept] β this is a bitmask type indicating how to interpret the regex. thesyntax_option_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. caveat time: a valid value of typesyntax_option_typeshall have exactly one ofECMAScript,basic,extended,awk,grep,egrepset π
OR besties
constexpr match_flag_type std::regex_constants::operator|(match_flag_type __a, match_flag_type __b)β [constexpr], [noexcept] β this is a bitmask type indicating regex matching rules. thematch_flag_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen πΈconstexpr syntax_option_type std::regex_constants::operator|(syntax_option_type __a, syntax_option_type __b)β [constexpr], [noexcept] β this is a bitmask type indicating how to interpret the regex. thesyntax_option_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. and the rule stands: a valid value of typesyntax_option_typeshall have exactly one ofECMAScript,basic,extended,awk,grep,egrepset πconstexpr match_flag_type &std::regex_constants::operator|=(match_flag_type &__a, match_flag_type __b)β [inline], [constexpr], [noexcept] β this is a bitmask type indicating regex matching rules. thematch_flag_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen π«Άconstexpr syntax_option_type &std::regex_constants::operator|=(syntax_option_type &__a, syntax_option_type __b)β [inline], [constexpr], [noexcept] β this is a bitmask type indicating how to interpret the regex. thesyntax_option_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. and yep, still true: a valid value of typesyntax_option_typeshall have exactly one ofECMAScript,basic,extended,awk,grep,egrepset π
the tilde finale ~
constexpr match_flag_type std::regex_constants::operator~(match_flag_type __a)β [constexpr], [noexcept] β this is a bitmask type indicating regex matching rules. thematch_flag_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. flip those bits, icon πconstexpr syntax_option_type std::regex_constants::operator~(syntax_option_type __a)β [constexpr], [noexcept] β this is a bitmask type indicating how to interpret the regex. thesyntax_option_typeis implementation defined but it is valid to perform bitwise operations on these values and expect the right thing to happen. and one more time for the people in the back: a valid value of typesyntax_option_typeshall have exactly one ofECMAScript,basic,extended,awk,grep,egrepset π
π Variable Documentation π
constexpr syntax_option_type std::regex_constants::__multiline [inline], [constexpr]β Extension: equivalent toregex_constants::multilinefor C++11 and C++14. Bestie, it's the backport vibe β¨constexpr syntax_option_type std::regex_constants::__polynomial [inline], [constexpr]β Extension: makes sure both the space complexity of the compiled regex and the time complexity execution are not exponential. If you specify it in a regex with back-references, the exceptionregex_constants::error_complexitywill be thrown. No cap, it's protecting you from a complexity meltdown πconstexpr syntax_option_type std::regex_constants::awk [inline], [constexpr]β says the grammar recognized by the regular expression engine is the one used by POSIX utilityawkin IEEE Std 1003.1-2001. This option is identical tosyntax_option_type extended, except that C-style escape sequences are supported. These sequences are:\\,\a,\b,\f,\n,\r,\t,\v,\&apos,,,&apos,,, and\ddd(wheredddis one, two, or three octal digits). awkward little escapes but iconic π¦constexpr syntax_option_type std::regex_constants::basic [inline], [constexpr]β says the grammar recognized by the regular expression engine is the one used by POSIX basic regular expressions in IEEE Std 1003.1-2001, Portable Operating System Interface (POSIX), Base Definitions and Headers, Section 9, Regular Expressions [IEEE, Information Technology -- Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. classic POSIX basic, no notes πconstexpr syntax_option_type std::regex_constants::collate [inline], [constexpr]β says character ranges of the form[a-b]should be locale sensitive. So your ranges are paying attention to the locale, periodt πconstexpr syntax_option_type std::regex_constants::ECMAScript [inline], [constexpr]β says the grammar recognized by the regular expression engine is the one used by ECMAScript in ECMA-262 [Ecma International, ECMAScript Language Specification, Standard Ecma-262, third edition, 1999], as modified in section [28.13]. This grammar is similar to that defined in the PERL scripting language but extended with elements found in the POSIX regular expression grammar. JavaScript grammar with POSIX sprinkles β¨constexpr syntax_option_type std::regex_constants::egrep [inline], [constexpr]β says the grammar recognized by the regular expression engine is the one used by POSIX utilitygrepwhen given the-Eoption in IEEE Std 1003.1-2001. This option is identical tosyntax_option_type extended, except that newlines are treated as whitespace. grep -E energy πconstexpr syntax_option_type std::regex_constants::extended [inline], [constexpr]β says the grammar recognized by the regular expression engine is the one used by POSIX extended regular expressions in IEEE Std 1003.1-2001, Portable Operating System Interface (POSIX), Base Definitions and Headers, Section 9, Regular Expressions. extended and proud πconstexpr match_flag_type std::regex_constants::format_default [inline], [constexpr]β when a regular expression match is to be replaced by a new string, the new string is constructed using the rules used by the ECMAScript replace function in ECMA- 262 [Ecma International, ECMAScript Language Specification, Standard Ecma-262, third edition, 1999], part 15.5.4.11String.prototype.replace. In addition, during search and replace operations all non-overlapping occurrences of the regular expression are located and replaced, and sections of the input that did not match the expression are copied unchanged to the output string.
Format strings (from ECMA-262 [15.5.4.11]):
$$β The dollar-sign itself ($)$&β The matched substring.$`β The portion of string that precedes the matched substring. This would bematch_results::prefix().$'β The portion of string that follows the matched substring. This would bematch_results::suffix().$nβ The nth capture, wherenis in[1,9]and$nis not followed by a decimal digit. Ifn <= match_results::size()and the nth capture is undefined, use the empty string instead. Ifn > match_results::size(), the result is implementation-defined.$nnβ The nnth capture, wherennis a two-digit decimal number on[01, 99]. Ifnn <= match_results::size()and the nth capture is undefined, use the empty string instead. Ifnn > match_results::size(), the result is implementation-defined.
constexpr match_flag_type std::regex_constants::format_first_only [inline], [constexpr]β when specified during a search and replace operation, only the first occurrence of the regular expression shall be replaced. first and only, literally πconstexpr match_flag_type std::regex_constants::format_no_copy [inline], [constexpr]β 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. no extra copy-paste energy πconstexpr match_flag_type std::regex_constants::format_sed [inline], [constexpr]β when a regular expression match is to be replaced by a new string, the new string is constructed using the rules used by the POSIXsedutility in IEEE Std 1003.1- 2001 [IEEE, Information Technology -- Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001]. sed girlies rise πΏconstexpr syntax_option_type std::regex_constants::grep [inline], [constexpr]β says the grammar recognized by the regular expression engine is the one used by POSIX utilitygrepin IEEE Std 1003.1-2001. This option is identical tosyntax_option_type basic, except that newlines are treated as whitespace. basic grep but newline-aware π«Άconstexpr syntax_option_type std::regex_constants::icase [inline], [constexpr]β says the matching of regular expressions against a character sequence shall be performed without regard to case. case? never heard of her πconstexpr match_flag_type std::regex_constants::match_any [inline], [constexpr]β if more than one match is possible then any match is an acceptable result. any match is a slay β¨constexpr match_flag_type std::regex_constants::match_continuous [inline], [constexpr]β the expression only matches a sub-sequence that begins atfirst. Referenced bystd::regex_iterator< _Bi_iter, _Ch_type, _Rx_traits >::operator++(). continuous matching behavior πconstexpr match_flag_type std::regex_constants::match_default [inline], [constexpr]β the default matching rules. no extra flags, just vibes πΈconstexpr match_flag_type std::regex_constants::match_not_bol [inline], [constexpr]β the first character in the sequence[first, last)is treated as though it is not at the beginning of a line, so the character(^)in the regular expression shall not match[first, first). not beginning-of-line, bestie π«constexpr match_flag_type std::regex_constants::match_not_bow [inline], [constexpr]β the expression\bis not matched against the sub-sequence[first,first). word boundary said no thank you π¦constexpr match_flag_type std::regex_constants::match_not_eol [inline], [constexpr]β the last character in the sequence[first, last)is treated as though it is not at the end of a line, so the character($)in the regular expression shall not match[last, last). not end-of-line either πconstexpr match_flag_type std::regex_constants::match_not_eow [inline], [constexpr]β the expression\bshould not be matched against the sub-sequence[last,last). end-of-word boundary, blocked πconstexpr match_flag_type std::regex_constants::match_not_null [inline], [constexpr]β the expression does not match an empty sequence. Referenced bystd::regex_iterator< _Bi_iter, _Ch_type, _Rx_traits >::operator++(). no empty-match nonsense πconstexpr match_flag_type std::regex_constants::match_prev_avail [inline], [constexpr]β--firstis a valid iterator position. When this flag is set then the flagsmatch_not_bolandmatch_not_boware ignored by the algorithmsregex_match,regex_search, andregex_replace, and by the iteratorsregex_iteratorandregex_token_iterator. Referenced bystd::regex_iterator< _Bi_iter, _Ch_type, _Rx_traits >::operator++(). previous char is available, so the rules shift π₯constexpr syntax_option_type std::regex_constants::multiline [inline], [constexpr]β says the^anchor matches at the beginning of a line, and the$anchor matches at the end of a line, not only at the beginning/end of the input. Valid for the ECMAScript syntax, ignored otherwise. Since C++17 πconstexpr syntax_option_type std::regex_constants::nosubs [inline], [constexpr]β says that when a regular expression is matched against a character container sequence, no sub-expression matches are to be stored in the suppliedmatch_resultsstructure. no capture groups saved, we're keeping it light πconstexpr syntax_option_type std::regex_constants::optimize [inline], [constexpr]β says 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. Otherwise it has no detectable effect on the program output. match speed era β‘
πΈ Author πΈ
Generated automatically by Doxygen for libstdc++ from the source code.
Source/version: libstdc++; page: std::regex_constants(3cxx); footer date: the one and only, doing its iconic little thing π«Άπ Byeee bestie β¨
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms