namespace
<regex>
std::regex_constants
regex constants
This namespace declares three bitmask types used with elements of the regex library along with constant values of these types:
Each of these
bitmask types may have been implemented in your library either as an enumerated type, an integer type, or a
bitset. In any case, it can take one or more flags of that same type as value by combining them using the
bitwise OR operator (
|):
1
|
bitmask_type object = flag1 | flag2 | flag3;
|
By providing these values under a specific namespace, you have the option to include this namespace (with
using namespace std::regex_constants) directly in your code in order to refer to these values more easily independently on whether you include the more generic namespace
std or not.
Bitmask type syntax_option_type
Aliased as member type
flag_type in
regex (and
basic_regex), it is used in the construction or assignment of
regex objects to specify the syntax used by the object. The possible values it can take are:
flag | effects on syntax | notes |
icase | Case insensitive | Regular expressions match without regard to case. |
nosubs | No sub-expressions | The match_results structure will not contain sub-expression matches. |
optimize | Optimize matching | Matching efficiency is preferred over efficiency constructing regex objects. |
collate | Locale sensitiveness | Character ranges, like "[a-b]", are affected by locale. |
ECMAScript | ECMAScript grammar | The regular expression follows one of these grammars.
One (and only one) of these six grammar flags needs to be set for the bitmask to have a valid value. |
basic | Basic POSIX grammar |
extended | Extended POSIX grammar |
awk | Awk POSIX grammar |
grep | Grep POSIX grammar |
egrep | Egrep POSIX grammar |
flag | effects on syntax | notes |
icase | Case insensitive | Regular expressions match without regard to case. |
nosubs | No sub-expressions | Sub-expressions are not considered to be marked.
The match_results structure will not contain sub-expression matches. |
optimize | Optimize matching | Matching efficiency is preferred over efficiency constructing regex objects. |
collate | Locale sensitiveness | Character ranges, like "[a-b]", are affected by locale. |
ECMAScript | ECMAScript grammar | The regular expression follows one of these grammars.
At most one of these six grammar flags can be set for the bitmask to have a valid value. If none is set, ECMAScript is assumed. |
basic | Basic POSIX grammar |
extended | Extended POSIX grammar |
awk | Awk POSIX grammar |
grep | Grep POSIX grammar |
egrep | Egrep POSIX grammar |
Bitmask type match_flag_type
Used as a parameter to functions
regex_match,
regex_search and
regex_replace and also as a parameter to the constructors of
regex_iterator and
regex_token_iterator.
flag | effects | notes |
match_default | Default | Default matching behavior.**. |
match_not_bol | Not Beginning-Of-Line | The first character is not considered a beginning of line ("^" does not match). |
match_not_eol | Not End-Of-Line | The last character is not considered an end of line ("$" does not match). |
match_not_bow | Not Beginning-Of-Word | The escape sequence "\b" does not match as a beginning-of-word. |
match_not_eow | Not End-Of-Word | The escape sequence "\b" does not match as an end-of-word. |
match_any | Any match | Any match is acceptable if more than one match is possible. |
match_not_null | Not null | Empty sequences do not match. |
match_continuous | Continuous | The expression must match a sub-sequence that begins at the first character.
Sub-sequences must begin at the first character to match. |
match_prev_avail | Previous Available | One or more characters exist before the first one. (match_not_bol and match_not_bow are ignored) |
format_default | Default formatting | Uses the standard formatting rules to replace matches (those used by ECMAScript's replace method).**. |
format_sed | sed formatting | Uses the same rules as the sed utility in POSIX to replace matches. |
format_no_copy | No copy | The sections in the target sequence that do not match the regular expression are not copied when replacing matches. |
format_first_only | First only | Only the first occurrence of a regular expression is replaced. |
** These constants have an
empty bitmask value and are ignored when combined with some other flag value.
Bitmask type error_type
Used as by the
regex_error to identify the kind of error that threw the exception:
flag | error |
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 brackets ([ and ]). |
error_paren | The expression contained mismatched parentheses (( and )). |
error_brace | The expression contained mismatched braces ({ and }). |
error_badbrace | The expression contained an invalid range between braces ({ and }). |
error_range | The expression contained an invalid character range. |
error_space | There was insufficient memory to convert the expression info a finite state machine. |
error_badrepeat | The expression contained a repeat specifier (one of *?+{) that 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. |