---
name: "std::regex_constants"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::regex_constants/3cxx"
---

# std::regex\_constants(3cxx)

ISO C++ 2011 namespace for options and flags used with std::regex.

## NAME

std::regex\_constants - ISO C++ 2011 namespace for options and flags used with std::regex.

## 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.  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**\
 constexpr **syntax\_option\_type** **\_\_multiline**\
 Extension: Equivalent to regex\_constants::multiline for C++11 and C++14.  constexpr **syntax\_option\_type** **\_\_polynomial**\
 constexpr **syntax\_option\_type** **operator&** (**syntax\_option\_type** \_\_a, **syntax\_option\_type** \_\_b)\
 This is a bitmask type indicating how to interpret the regex.  constexpr **syntax\_option\_type** **operator\|** (**syntax\_option\_type** \_\_a, **syntax\_option\_type** \_\_b)\
 This is a bitmask type indicating how to interpret the regex.  constexpr **syntax\_option\_type** **operator^** (**syntax\_option\_type** \_\_a, **syntax\_option\_type** \_\_b)\
 This is a bitmask type indicating how to interpret the regex.  constexpr **syntax\_option\_type** **operator~** (**syntax\_option\_type** \_\_a)\
 This is a bitmask type indicating how to interpret the regex.  constexpr **syntax\_option\_type** & **operator&=** (**syntax\_option\_type** &\_\_a, **syntax\_option\_type** \_\_b)\
 This is a bitmask type indicating how to interpret the regex.  constexpr **syntax\_option\_type** & **operator\|=** (**syntax\_option\_type** &\_\_a, **syntax\_option\_type** \_\_b)\
 This is a bitmask type indicating how to interpret the regex.  constexpr **syntax\_option\_type** & **operator^=** (**syntax\_option\_type** &\_\_a, **syntax\_option\_type** \_\_b)\
 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.  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.  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**\
 constexpr **match\_flag\_type** **operator&** (**match\_flag\_type** \_\_a, **match\_flag\_type** \_\_b)\
 This is a bitmask type indicating regex matching rules.  constexpr **match\_flag\_type** **operator\|** (**match\_flag\_type** \_\_a, **match\_flag\_type** \_\_b)\
 This is a bitmask type indicating regex matching rules.  constexpr **match\_flag\_type** **operator^** (**match\_flag\_type** \_\_a, **match\_flag\_type** \_\_b)\
 This is a bitmask type indicating regex matching rules.  constexpr **match\_flag\_type** **operator~** (**match\_flag\_type** \_\_a)\
 This is a bitmask type indicating regex matching rules.  constexpr **match\_flag\_type** & **operator&=** (**match\_flag\_type** &\_\_a, **match\_flag\_type** \_\_b)\
 This is a bitmask type indicating regex matching rules.  constexpr **match\_flag\_type** & **operator\|=** (**match\_flag\_type** &\_\_a, **match\_flag\_type** \_\_b)\
 This is a bitmask type indicating regex matching rules.  constexpr **match\_flag\_type** & **operator^=** (**match\_flag\_type** &\_\_a, **match\_flag\_type** \_\_b)\
 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** }\
 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.

## Enumeration Type Documentation

### enum std::regex\_constants::error\_type

The expression contained an invalid collating element name.

### 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.

### 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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

## Function Documentation

### constexpr error\_type std::regex\_constants::error\_backref (\_S\_error\_backref)` [inline]`, ` [constexpr]`

The expression contained an invalid back reference.

### constexpr error\_type std::regex\_constants::error\_badbrace (\_S\_error\_badbrace)` [inline]`, ` [constexpr]`

The expression contained an invalid range in a {} expression.

### constexpr error\_type std::regex\_constants::error\_badrepeat (\_S\_error\_badrepeat)` [inline]`, ` [constexpr]`

One of *\*?+{* was not preceded by a valid regular expression.

### constexpr error\_type std::regex\_constants::error\_brace (\_S\_error\_brace)` [inline]`, ` [constexpr]`

The expression contained mismatched { and }

### constexpr error\_type std::regex\_constants::error\_brack (\_S\_error\_brack)` [inline]`, ` [constexpr]`

The expression contained mismatched \[ and \].

### constexpr error\_type std::regex\_constants::error\_collate (\_S\_error\_collate)` [inline]`, ` [constexpr]`

The expression contained an invalid collating element name.

### 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.

### constexpr error\_type std::regex\_constants::error\_ctype (\_S\_error\_ctype)` [inline]`, ` [constexpr]`

The expression contained an invalid character class name.

### constexpr error\_type std::regex\_constants::error\_escape (\_S\_error\_escape)` [inline]`, ` [constexpr]`

The expression contained an invalid escaped character, or a trailing escape.

### constexpr error\_type std::regex\_constants::error\_paren (\_S\_error\_paren)` [inline]`, ` [constexpr]`

The expression contained mismatched ( and ).

### 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.

### 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.

### 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.

### constexpr match\_flag\_type std::regex\_constants::operator& (match\_flag\_type \_\_a, match\_flag\_type \_\_b)` [inline]`, ` [constexpr]`

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.

### constexpr syntax\_option\_type std::regex\_constants::operator& (syntax\_option\_type \_\_a, syntax\_option\_type \_\_b)` [inline]`, ` [constexpr]`

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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

### constexpr match\_flag\_type & std::regex\_constants::operator&= (match\_flag\_type & \_\_a, match\_flag\_type \_\_b)` [inline]`, ` [constexpr]`

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.

### constexpr syntax\_option\_type & std::regex\_constants::operator&= (syntax\_option\_type & \_\_a, syntax\_option\_type \_\_b)` [inline]`, ` [constexpr]`

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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

### constexpr match\_flag\_type std::regex\_constants::operator^ (match\_flag\_type \_\_a, match\_flag\_type \_\_b)` [inline]`, ` [constexpr]`

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.

### constexpr syntax\_option\_type std::regex\_constants::operator^ (syntax\_option\_type \_\_a, syntax\_option\_type \_\_b)` [inline]`, ` [constexpr]`

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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

### constexpr match\_flag\_type & std::regex\_constants::operator^= (match\_flag\_type & \_\_a, match\_flag\_type \_\_b)` [inline]`, ` [constexpr]`

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.

### constexpr syntax\_option\_type & std::regex\_constants::operator^= (syntax\_option\_type & \_\_a, syntax\_option\_type \_\_b)` [inline]`, ` [constexpr]`

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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

### constexpr match\_flag\_type std::regex\_constants::operator\| (match\_flag\_type \_\_a, match\_flag\_type \_\_b)` [inline]`, ` [constexpr]`

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.

### constexpr syntax\_option\_type std::regex\_constants::operator\| (syntax\_option\_type \_\_a, syntax\_option\_type \_\_b)` [inline]`, ` [constexpr]`

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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

### constexpr match\_flag\_type & std::regex\_constants::operator\|= (match\_flag\_type & \_\_a, match\_flag\_type \_\_b)` [inline]`, ` [constexpr]`

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.

### constexpr syntax\_option\_type & std::regex\_constants::operator\|= (syntax\_option\_type & \_\_a, syntax\_option\_type \_\_b)` [inline]`, ` [constexpr]`

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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

### constexpr match\_flag\_type std::regex\_constants::operator~ (match\_flag\_type \_\_a)` [inline]`, ` [constexpr]`

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.

### constexpr syntax\_option\_type std::regex\_constants::operator~ (syntax\_option\_type \_\_a)` [inline]`, ` [constexpr]`

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.

A valid value of type syntax\_option\_type shall have exactly one of the elements `ECMAScript`, `basic`, `extended`, `awk`, `grep`, `egrep` set.

## Variable Documentation

### constexpr syntax\_option\_type std::regex\_constants::\_\_multiline` [inline]`, ` [constexpr]`

Extension: Equivalent to regex\_constants::multiline for C++11 and C++14.

### constexpr syntax\_option\_type std::regex\_constants::\_\_polynomial` [inline]`, ` [constexpr]`

Extension: Ensure both space complexity of compiled regex and time complexity execution are not exponential. If specified in a regex with back-references, the exception regex\_constants::error\_complexity will be thrown.

### constexpr syntax\_option\_type std::regex\_constants::awk` [inline]`, ` [constexpr]`

Specifies that the grammar recognized by the regular expression engine is that used by POSIX utility awk in IEEE Std 1003.1-2001. This option is identical to syntax\_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 (where ddd is one, two, or three octal digits).

### constexpr syntax\_option\_type std::regex\_constants::basic` [inline]`, ` [constexpr]`

Specifies that the grammar recognized by the regular expression engine is that 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\].

### constexpr syntax\_option\_type std::regex\_constants::collate` [inline]`, ` [constexpr]`

Specifies that character ranges of the form \[a-b\] should be locale sensitive.

### constexpr syntax\_option\_type std::regex\_constants::ECMAScript` [inline]`, ` [constexpr]`

Specifies that the grammar recognized by the regular expression engine is that 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.

### constexpr syntax\_option\_type std::regex\_constants::egrep` [inline]`, ` [constexpr]`

Specifies that the grammar recognized by the regular expression engine is that used by POSIX utility grep when given the -E option in IEEE Std 1003.1-2001. This option is identical to syntax\_option\_type extended, except that newlines are treated as whitespace.

### constexpr syntax\_option\_type std::regex\_constants::extended` [inline]`, ` [constexpr]`

Specifies that the grammar recognized by the regular expression engine is that 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.

### 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.11 String.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 be match\_results::prefix().

- •

  $' The portion of *string* that follows the matched substring. This would be match\_results::suffix().

- •

  $n The nth capture, where n is in \[1,9\] and $n is not followed by a decimal digit. If n \<= match\_results::size() and the nth capture is undefined, use the empty string instead. If n \> match\_results::size(), the result is implementation-defined.

- •

  $nn The nnth capture, where nn is a two-digit decimal number on \[01, 99\]. If nn \<= match\_results::size() and the nth capture is undefined, use the empty string instead. If nn \> 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.

### 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.

### 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 POSIX sed utility in IEEE Std 1003.1- 2001 \[IEEE, Information Technology -- Portable Operating System Interface (POSIX), IEEE Standard 1003.1-2001\].

### constexpr syntax\_option\_type std::regex\_constants::grep` [inline]`, ` [constexpr]`

Specifies that the grammar recognized by the regular expression engine is that used by POSIX utility grep in IEEE Std 1003.1-2001. This option is identical to syntax\_option\_type basic, except that newlines are treated as whitespace.

### constexpr syntax\_option\_type std::regex\_constants::icase` [inline]`, ` [constexpr]`

Specifies that the matching of regular expressions against a character sequence shall be performed without regard to case.

### 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.

### constexpr match\_flag\_type std::regex\_constants::match\_continuous` [inline]`, ` [constexpr]`

The expression only matches a sub-sequence that begins at first .

### constexpr match\_flag\_type std::regex\_constants::match\_default` [inline]`, ` [constexpr]`

The default matching rules.

### 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).

### constexpr match\_flag\_type std::regex\_constants::match\_not\_bow` [inline]`, ` [constexpr]`

The expression \\b is not matched against the sub-sequence \[first,first).

### 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).

### constexpr match\_flag\_type std::regex\_constants::match\_not\_eow` [inline]`, ` [constexpr]`

The expression \\b should not be matched against the sub-sequence \[last,last).

### constexpr match\_flag\_type std::regex\_constants::match\_not\_null` [inline]`, ` [constexpr]`

The expression does not match an empty sequence.

### constexpr match\_flag\_type std::regex\_constants::match\_prev\_avail` [inline]`, ` [constexpr]`

`--first` is a valid iterator position. When this flag is set then the flags `match_not_bol` and `match_not_bow` are ignored by the algorithms `regex_match`, `regex_search`, and `regex_replace`, and by the iterators `regex_iterator` and `regex_token_iterator`.

### constexpr syntax\_option\_type std::regex\_constants::multiline` [inline]`, ` [constexpr]`

Specifies that 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]`

Specifies that when a regular expression is matched against a character container sequence, no sub-expression matches are to be stored in the supplied match\_results structure.

### constexpr syntax\_option\_type std::regex\_constants::optimize` [inline]`, ` [constexpr]`

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. Otherwise it has no detectable effect on the program output.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
