class template
<regex>

std::basic_regex

template <class charT, class traits = regex_traits<charT> > class basic_regex;
Regular expression
A regular expression is an object defining a particular pattern to be matched against a sequence of characters using the tools of the standard regex library.

Such objects are essentially constructed from a sequence of characters that can include several wildcards and constraints to define the set of rules (the pattern) that make a sequence of characters qualify as a match. By default, regex patterns follow the ECMAScript syntax.

basic_regex object do not conduct the matches directly through any of its members. Instead, they are used as arguments for regex algorithms (regex_match, regex_search and regex_replace) and regex iterator adaptors (regex_iterator and regex_token_iterator) that perform these matches using the rules specified when constructing the basic_regex object.

Two instantiations of this basic class exist in the standard header <regex> for the most common cases:
1
2
typedef basic_regex<char>    regex;
typedef basic_regex<wchar_t> wregex;

Template parameters

charT
The character type.
traits
The regex traits to be used by regex operations on this object.
This can either be an instantiation of the regex_traits class template or a custom class with the same members.

Template instantiations


Member types

The following aliases are member types of basic_regex. They are widely used as parameter and return types by member functions:

member typedefinitionnotes
value_typeThe first template parameter (charT)The character type.
traits_typeThe second template parameter (traits)<char>Regex traits (defaults to regex_traits).
string_typetraits::string_typeString type (string for regex, wstring for wregex).
flag_typeregex_constants::syntax_option_type
locale_typetraits::locale_typelocale for the standard regex_traits.

Member functions


Assignment


Const operations


Locale


Swap


Non-member functions


Member constants

These member constants are aliases of the homonym constants under the std::regex_constants namespace (see regex_constants for more details):
flag*effects on syntaxNotes
icaseCase insensitiveRegular expressions match without regard to case.
nosubsNo sub-expressionsThe match_results structure will not contain sub-expression matches.
optimizeOptimize matchingMatching efficiency is preferred over efficiency constructing regex objects.
collateLocale sensitivenessCharacter ranges, like "[a-b]", are affected by locale.
ECMAScriptECMAScript grammarThe 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.
basicBasic POSIX grammar
extendedExtended POSIX grammar
awkAwk POSIX grammar
grepGrep POSIX grammar
egrepEgrep POSIX grammar


See also