31 Regular expressions library [re]

31.5 Namespace std​::​regex_­constants [re.const]

The namespace std​::​regex_­constants holds symbolic constants used by the regular expression library.
This namespace provides three types, syntax_­option_­type, match_­flag_­type, and error_­type, along with several constants of these types.

31.5.1 Bitmask type syntax_­option_­type [re.synopt]

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;
}
The type syntax_­option_­type is an implementation-defined bitmask type.
Setting its elements has the effects listed in Table 130.
A valid value of type syntax_­option_­type shall have at most one of the grammar elements ECMAScript, basic, extended, awk, grep, egrep, set.
If no grammar element is set, the default grammar is ECMAScript.
Table 130syntax_­option_­type effects
Element
Effect(s) if set
icase
Specifies that matching of regular expressions against a character container sequence shall be performed without regard to case.
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 structure.
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.
Otherwise it has no detectable effect on the program output.
collate
Specifies that character ranges of the form "[a-b]" shall be locale sensitive.
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].
basic
Specifies that the grammar recognized by the regular expression engine shall be that used by basic regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions.
extended
Specifies that the grammar recognized by the regular expression engine shall be that used by extended regular expressions in POSIX, Base Definitions and Headers, Section 9, Regular Expressions.
awk
Specifies that the grammar recognized by the regular expression engine shall be that used by the utility awk in POSIX.
grep
Specifies that the grammar recognized by the regular expression engine shall be that used by the utility grep in POSIX.
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.
multiline
Specifies that ^ shall match the beginning of a line and $ shall match the end of a line, if the ECMAScript engine is selected.

31.5.2 Bitmask type match_­flag_­type [re.matchflag]

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;
}
The type match_­flag_­type is an implementation-defined bitmask type.
The constants of that type, except for match_­default and format_­default, are bitmask elements.
The match_­default and format_­default constants are empty bitmasks.
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 131 for any bitmask elements set.
Table 131regex_­constants​::​match_­flag_­type effects when obtaining a match against a character container sequence [first, last).
Element
Effect(s) if set
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).
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).
match_­not_­bow
The expression "\\b" shall not match the sub-sequence [first, first).
match_­not_­eow
The expression "\\b" shall not match the sub-sequence [last, last).
match_­any
If more than one match is possible then any match is an acceptable result.
match_­not_­null
The expression shall not match an empty sequence.
match_­continuous
The expression shall only match a sub-sequence that begins at first.
match_­prev_­avail
--first is a valid iterator position.
When this flag is set the flags match_­not_­bol and match_­not_­bow shall be ignored by the regular expression algorithms and iterators.
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.
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.
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.
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.
format_­first_­only
When specified during a search and replace operation, only the first occurrence of the regular expression shall be replaced.

31.5.3 Implementation-defined error_­type [re.err]

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;
}
The type error_­type is an implementation-defined enumerated type.
Values of type error_­type represent the error conditions described in Table 132:
Table 132error_­type values in the C locale
Value
Error condition
error_­collate
The expression contained an invalid collating element name.
error_­ctype
The expression contained an invalid character class name.
error_­escape
The expression contained an invalid escaped character, or a trailing escape.
error_­backref
The expression contained an invalid back reference.
error_­brack
The expression contained mismatched [ and ].
error_­paren
The expression contained mismatched ( and ).
error_­brace
The expression contained mismatched { and }
error_­badbrace
The expression contained an invalid range in a {} expression.
error_­range
The expression contained an invalid character range, such as [b-a] in most encodings.
error_­space
There was insufficient memory to convert the expression into a finite state machine.
error_­badrepeat
One of *?+{ was not preceded by a valid regular expression.
error_­complexity
The complexity of an attempted match against a regular expression exceeded a pre-set level.
error_­stack
There was insufficient memory to determine whether the regular expression could match the specified character sequence.