<regex>
[added with C++11]
basic_regex
· error_type
· match_flag_type
· match_results
· regex_constants
· regex_error
· regex_iterator
· regex_traits
· regex_traits<char>
· regex_traits<wchar_t>
· regex_token_iterator
· sub_match
· syntax_option_type
cmatch
· cregex_iterator
· cregex_token_iterator
· csub_match
· regex
· smatch
· sregex_iterator
· sregex_token_iterator
· ssub_match
· wcmatch
· wcregex_iterator
· wcregex_token_iterator
· wcsub_match
· wregex
· wsmatch
· wsregex_iterator
· wsregex_token_iterator
· wssub_match
regex_match
· regex_replace
· regex_search
operator==
· operator!=
· operator<
· operator<=
· operator>
· operator>=
· operator<<
· swap
Include the TR1
header <regex>
to define a template class
to parse regular expressions
and several template classes and functions to search text for matches to a
regular expression object.
To create a regular expression object use the template class basic_regex or one of its specializations, regex and wregex, along with the syntax flags of type syntax_option_type.
To search text for matches to a regular expression object use the template functions regex_match and regex_search, along with the match flags of type match_flag_type. These functions return their results using the template class match_results and its specializations, cmatch, wcmatch, smatch, and wsmatch, along with the template class sub_match and its specializations, csub_match, wcsub_match, ssub_match, and wssub_match.
To replace text that matches a regular expression object use the template function regex_replace, along with the match flags of type match_flag_type.
To iterate through multiple matches of a regular expression object use the template classes regex_iterator and regex_token_iterator or one of their specializations, cregex_iterator, sregex_iterator, wcregex_iterator, wsregex_iterator, cregex_token_iterator, sregex_token_iterator, wcregex_token_iterator, and wsregex_token_iterator, along with the match flags of type match_flag_type.
To modify some of the details of the grammar of regular expressions write a class that implements the regular expression traits.
namespace std { // TEMPLATE CLASS regex_traits AND basic_regex template<class Elem> struct regex_traits; template<> struct regex_traits<char>; template<> struct regex_traits<wchar_t>; template<class Elem, class RXtraits = regex_traits<Elem>, class basic_regex; typedef basic_regex<char> regex; typedef basic_regex<wchar_t> wregex; // TEMPLATE CLASS sub_match template<class BidIt> class sub_match; typedef sub_match<const char*> csub_match; typedef sub_match<const wchar_t*> wcsub_match; typedef sub_match<string::const_iterator> ssub_match; typedef sub_match<wstring::const_iterator> wssub_match; // TEMPLATE CLASS match_results template<class BidIt, class Alloc = allocator<typename iterator_traits<BidIt>::value_type> > class match_results; typedef match_results<const char*> cmatch; typedef match_results<const wchar_t*> wcmatch; typedef match_results<string::const_iterator> smatch; typedef match_results<wstring::const_iterator> wsmatch; // NAMESPACE regex_constants namespace regex_constants { typedef T1 syntax_option_type; static const syntax_option_type awk, basic, collate, ECMAScript, egrep, extended, grep, icase, nosubs, optimize; typedef T2 match_flag_type; static const match_flag_type match_any, match_default, match_not_bol, match_not_bow, match_continuous, match_not_eol, match_not_eow, match_not_null, match_prev_avail; typedef T3 error_type; static const error_type error_badbrace, error_badrepeat, error_brace, error_brack, error_collate, error_complexity, error_ctype, error_escape, error_paren, error_range, error_space, error_stack, error_backref; } // namespace regex_constants // CLASS regex_error class regex_error; // TEMPLATE FUNCTION regex_match template<class BidIt, class Alloc, class Elem, class RXtraits> bool regex_match(BidIt first, Bidit last, match_results<BidIt, Alloc>& match, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class BidIt, class Elem, class RXtraits> bool regex_match(BidIt first, Bidit last, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class Elem, class Alloc, class RXtraits> bool regex_match(const Elem *ptr, match_results<const Elem *, Alloc>& match, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class Elem, class RXtraits> bool regex_match(const Elem *ptr, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits> bool regex_match(const basic_string<Elem, IOtraits, IOalloc>& str, match_results<typename basic_string<Elem, IOtraits, IOalloc>::const_iterator, Alloc>& match, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Elem, class RXtraits> bool regex_match(const basic_string<Elem, IOtraits, IOalloc>& match, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); // TEMPLATE FUNCTION regex_search template<class BidIt, class Alloc, class Elem, class RXtraits> bool regex_search(BidIt first, Bidit last, match_results<BidIt, Alloc>& match, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class BidIt, class Elem, class RXtraits> bool regex_search(BidIt first, Bidit last, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class Elem, class Alloc, class RXtraits> bool regex_search(const Elem *ptr, match_results<const Elem*, Alloc>& match, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class Elem, class RXtraits> bool regex_search(const Elem *ptr, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits> bool regex_search(const basic_string<Elem, IOtraits, IOalloc>& str, match_results<typename basic_string<Elem, IOtraits, IOalloc>::const_iterator, Alloc>& match, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Elem, class RXtraits> bool regex_search(const basic_string<Elem, IOtraits, IOalloc>& str, const basic_regex<Elem, RXtraits>& re, match_flag_type flags = match_default); // TEMPLATE FUNCTION regex_replace template<class OutIt, class BidIt, class RXtraits, class Elem, class Traits, class Alloc> OutIt regex_replace(OutIt out, BidIt first, BidIt last, const basic_regex<Elem, RXtraits>& re, const basic_string<Elem, Traits, Alloc>& fmt, match_flag_type flags = match_default); template<class OutIt, class BidIt, class RXtraits, class Elem> OutIt regex_replace(OutIt out, BidIt first, BidIt last, const basic_regex<Elem, RXtraits>& re, const Elem *fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem, class Traits1, class Alloc1, class Traits2, class Alloc2> basic_string<Elem, Traits1, Alloc1> regex_replace( const basic_string<Elem, Traits1, Alloc1>& str, const basic_regex<Elem, RXtraits>& re, const basic_string<Elem, Traits2, Alloc2>& fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem, class Traits1, class Alloc1> basic_string<Elem, Traits1, Alloc1> regex_replace( const basic_string<Elem, Traits1, Alloc1>& str, const basic_regex<Elem, RXtraits>& re, const Elem *fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem, class Traits2, class Alloc2> basic_string<Elem> regex_replace( const Elem *str, const basic_regex<Elem, RXtraits>& re, const basic_string<Elem, Traits2, Alloc2>& fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem> basic_string<Elem> regex_replace( const Elem *str, const basic_regex<Elem, RXtraits>& re, const Elem *fmt, match_flag_type flags = match_default); // REGULAR EXPRESSION ITERATORS template<class BidIt, class Elem = iterator_traits<BidIt>::value_type, class RXtraits = regex_traits<Elem> > class regex_iterator; typedef regex_iterator<const char*> cregex_iterator; typedef regex_iterator<const wchar_t*> wcregex_iterator; typedef regex_iterator<string::const_iterator> sregex_iterator; typedef regex_iterator<wstring::const_iterator> wsregex_iterator; template<class BidIt, class Elem = iterator_traits<BidIt>::value_type, class RXtraits = regex_traits<Elem> > class regex_token_iterator; typedef regex_token_iterator<const char*> cregex_token_iterator; typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator; typedef regex_token_iterator<string::const_iterator> sregex_token_iterator; typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator; // STREAM INSERTER template<class Elem, class IOtraits, class Alloc, class BidIt> basic_ostream<Elem, IOtraits>& operator<<(basic_ostream<Elem, IOtraits>& os, const sub_match<BidIt>& submatch); // TEMPLATE swap FUNCTIONS template<class Elem, class RXtraits> void swap(basic_regex<Elem, RXtraits>& left, basic_regex<Elem, RXtraits>& right) throw(); template<class Elem, class IOtraits, class BidIt, class Alloc> void swap(match_results<BidIt, Alloc>& left, match_results<BidIt, Alloc>& right) throw(); // COMPARISON OPERATORS FOR match_results template<class BidIt, class Alloc> bool operator==(const match_results<BidIt, Alloc>& left, const match_results<BidIt, Alloc>& right); template<class BidIt, class Alloc> bool operator!=(const match_results<BidIt, Alloc>& left, const match_results<BidIt, Alloc>& right); // COMPARISON OPERATORS FOR sub_match template<class BidIt> bool operator==(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt> bool operator!=(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt> bool operator<(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt> bool operator<=(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt> bool operator>(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt> bool operator>=(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator==( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator!=( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<=( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>=( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator==(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt, class IOtraits, class Alloc> bool operator!=(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<=(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>=(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt> bool operator==(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator!=(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator<(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator<=(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator>(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator>=(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator==(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type*); template<class BidIt> bool operator!=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type*); template<class BidIt> bool operator<(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type*); template<class BidIt> bool operator<=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type*); template<class BidIt> bool operator>(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type*); template<class BidIt> bool operator>=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type*); template<class BidIt> bool operator==(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator!=(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator<(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator<=(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator>(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator>=(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator==(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); template<class BidIt> bool operator!=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); template<class BidIt> bool operator<(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); template<class BidIt> bool operator<=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); template<class BidIt> bool operator>(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); template<class BidIt> bool operator>=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); namespace tr1 { using std::basic_regex; using std::match_results; [added with C++11] using std::regex; using std::regex_error; using std::regex_iterator; using std::regex_match; using std::regex_replace; using std::regex_search; using std::regex_token_iterator; using std::regex_traits; using std::sub_match; } // namespace tr1 } // namespace std
basic_regex
template<class Elem, class RXtraits = regex_traits<Elem>, class basic_regex { public: typedef Elem value_type; typedef RXtraits traits_type [added with C++11]; typedef regex_constants::syntax_option_type flag_type; typedef typename RXtraits::locale_type locale_type; typedef typename RXtraits::string_type locale_type [added with C++11]; basic_regex(); basic_regex(initializer_list<Ty> init, flag_type flags = ECMAScript); [added with C++11] explicit basic_regex(const Elem *ptr, flag_type flags = ECMAScript); basic_regex(const Elem *ptr, size_type len, flag_type flags = ECMAScript); basic_regex(const basic_regex& right); basic_regex(basic_regex&& right) noexcept; [added with C++11] template<class STtraits, class STalloc> explicit basic_regex(const basic_string<Elem, STtraits, STalloc>& str, flag_type flags = ECMAScript); template<class FwdIt> explicit basic_regex(FwdIt first, FwdIt last, flag_type flags = ECMAScript); basic_regex& operator=(initializer_list<Ty> init) [added with C++11] basic_regex& operator=(const basic_regex& right); basic_regex& operator=(basic_regex&& right) noexcept; [added with C++11] basic_regex& operator=(const Elem *ptr); template<class STtraits, class STalloc> basic_regex& operator=(const basic_string<Elem, STtraits, STalloc>& str); basic_regex& assign(initializer_list<Ty> init, flag_type flags = ECMAScript) [added with C++11] basic_regex& assign(const basic_regex& right); basic_regex& assign(basic_regex&& right) noexcept; [added with C++11] basic_regex& assign(const Elem *ptr, flag_type flags = ECMAScript); basic_regex& assign(const Elem *ptr, size_type len, flag_type flags = ECMAScript); template<class STtraits, class STalloc> basic_regex& assign(const basic_string<Elem, STtraits, STalloc>& str, flag_type flags = ECMAScript); template<class InIt> basic_regex& assign(InIt first, InIt last, flag_type flags = ECMAScript); locale_type imbue(locale_type loc); locale_type getloc() const; void swap(basic_regex& other) throw(); unsigned mark_count() const; flag_type flags() const; static const flag_type icase = regex_constants::icase; static const flag_type nosubs = regex_constants::nosubs; static const flag_type optimize = regex_constants::optimize; static const flag_type collate = regex_constants::collate; static const flag_type ECMAScript = regex_constants::ECMAScript; static const flag_type basic = regex_constants::basic; static const flag_type extended = regex_constants::extended; static const flag_type awk = regex_constants::awk; static const flag_type grep = regex_constants::grep; static const flag_type egrep = regex_constants::egrep; private: RXtraits traits; // exposition only };
The template class describes an object that holds a regular expression. Objects of this template class can be passed to the template functions regex_match, regex_search, and regex_replace, along with suitable text string arguments, to search for text that matches the regular expression. The TR1 library provides two specializations of this template class, with the type definitions regex for elements of type char, and wregex for elements of type wchar_t.
The template argument RXtraits
describes various important properties
of the syntax of the regular expressions that the template class supports. A class
that specifies these
regular expression traits
must have the same external interface as an object of
template class regex_traits.
Some functions take an operand sequence that defines a regular expression. You can specify such an operand sequence several ways:
ilist
-- a sequence of elements described by an object of class
initializer_list<Ty>
,
for some element type Ty
compatible with the regular expression
element typeptr
-- a null-terminated sequence (such as a C string, for Elem
of type char) beginning at ptr
(which must not be a null pointer),
where the terminating element is the value value_type()
and is not part of
the operand sequenceptr
, count
-- a sequence of count
elements
beginning at ptr
(which must not be a null pointer)str
-- the sequence specified by the basic_string
object str
first
, last
-- a sequence of elements delimited by
the iterators first
and last
, in the range [first, last)
right
-- the basic_regex
object right
These member functions also take an argument flags
that specifies various options for the interpretation of the regular
expression in addition to those described by the RXtraits
type.
basic_regex::assign
basic_regex& assign(initializer_list<Ty> init, flag_type flags = ECMAScript) [added with C++11] basic_regex& assign(const basic_regex& right); basic_regex& assign(basic_regex&& right) noexcept; [added with C++11] basic_regex& assign(const Elem *ptr, flag_type flags = ECMAScript); basic_regex& assign(const Elem *ptr, size_type len, flag_type flags = ECMAScript); template<class STtraits, class STalloc> basic_regex& assign(const basic_string<Elem, STtraits, STalloc>& str, flag_type flags = ECMAScript); template<class InIt> basic_regex& assign(InIt first, InIt last, flag_type flags = ECMAScript);
The member functions each replace the regular expression held by *this
with
the regular expression described by the operand sequence,
then return *this
.
basic_regex::awk
static const flag_type awk = regex_constants::awk;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::awk.
basic_regex::basic
static const flag_type basic = regex_constants::basic;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::basic.
basic_regex::basic_regex
basic_regex(); basic_regex(initializer_list<Ty> init, flag_type flags = ECMAScript); [added with C++11] template<class STtraits, class STalloc> explicit basic_regex(const basic_string<Elem, STtraits, STalloc>& str, flag_type flags = ECMAScript); template<class FwdIt> explicit basic_regex(FwdIt first, FwdIt last, flag_type flags = ECMAScript); explicit basic_regex(const Elem *ptr, flag_type flags = ECMAScript); explicit basic_regex(const Elem *ptr, size_type len, flag_type flags); basic_regex(const basic_regex& right); basic_regex(basic_regex&& right) noexcept; [added with C++11]
All constructors store a default-constructed object of type RXtraits
.
The first constructor constructs an empty
object. The second constructor constructs an object that holds
the regular expression described by an object of class
initializer_list<Ty>
.
The other constructors construct an object that holds
the regular expression described by
the operand sequence.
An empty basic_regex
object does not
match any character sequence when passed to regex_match,
regex_search, or
regex_replace.
basic_regex::collate
static const flag_type collate = regex_constants::collate;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::collate.
basic_regex::ECMAScript
static const flag_type ECMAScript = regex_constants::ECMAScript;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::ECMAScript.
basic_regex::egrep
static const flag_type egrep = regex_constants::egrep;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::egrep.
basic_regex::extended
static const flag_type extended = regex_constants::extended;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::extended.
basic_regex::flag_type
typedef regex_constants::syntax_option_type flag_type;
The type is a synonym for regex_constants::syntax_option_type.
basic_regex::flags
flag_type flags() const;
The member function returns the value of the flag_type
argument
passed to the most recent call to one of the
assign member functions or,
if no such call has been made, the value passed to the constructor.
basic_regex::getloc
locale_type getloc() const;
The member function returns traits.getloc()
.
basic_regex::grep
static const flag_type grep = regex_constants::grep;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::grep.
basic_regex::icase
static const flag_type icase = regex_constants::icase;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::icase.
basic_regex::imbue
locale_type imbue(locale_type loc);
The member function empties *this
and
returns traits.imbue(loc)
.
basic_regex::locale_type
typedef typename RXtraits::locale_type locale_type;
The type is a synonym for regex_traits::locale_type.
basic_regex::mark_count
unsigned mark_count() const;
The member function returns the number of capture groups in the regular expression.
basic_regex::nosubs
static const flag_type nosubs = regex_constants::nosubs;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::nosubs.
basic_regex::operator=
basic_regex& operator=(initializer_list<Ty> init) [added with C++11] basic_regex& operator=(const basic_regex& right); basic_regex& operator=(basic_regex&& right) noexcept; [added with C++11] basic_regex& operator=(const Elem *str); template<class STtraits, class STalloc> basic_regex& operator=(const basic_string<Elem, STtraits, STalloc>& str);
The first member operator effectively returns
assign(init)
.
The remaining member operators each replace the regular expression held by
*this
with the regular expression described by the
operand sequence, then return
*this
.
basic_regex::optimize
static const flag_type optimize = regex_constants::optimize;
The constant can be passed to the constructors or the assign member functions. It has the value regex_constants::optimize.
basic_regex::string_type
typedef typename RXtraits::string_type string_type; [added with C++11]
The type is a synonym for regex_traits::string_type.
basic_regex::swap
void swap(basic_regex& right) throw();
The member function swaps the regular expressions between *this
and right
. It does so in constant time and throws no exceptions.
basic_regex::traits_type
typedef RXtraits traits_type; [added with C++11]
The type is a synonym for the template parameter RXtraits
.
basic_regex::value_type
typedef Elem value_type;
The type is a synonym for the template parameter Elem
.
cmatch
typedef match_results<const char*> cmatch;
The type describes a specialization of template class match_results for iterators of type const char*.
cregex_iterator
typedef regex_iterator<const char*> cregex_iterator;
The type describes a specialization of template class regex_iterator for iterators of type const char*.
cregex_token_iterator
typedef regex_token_iterator<const char*> cregex_token_iterator;
The type describes a specialization of template class regex_token_iterator for iterators of type const char*.
csub_match
typedef sub_match<const char*> csub_match;
The type describes a specialization of template class sub_match for iterators of type const char*.
match_results
template<class BidIt, class Alloc = allocator<typename iterator_traits<BidIt>::value_type> > class match_results { public: explicit match_results(const Alloc& alloc = Alloc()); match_results(const match_results& right); match_results(match_results&& right); [added with C++11] match_results& operator=(const match_results& right); match_results& operator=(match_results&& right) noexcept; [added with C++11] difference_type position(size_type sub = 0) const; difference_type length(size_type sub = 0) const; string_type str(size_type sub = 0) const; const_reference operator[](size_type n) const; const_reference prefix() const; const_reference suffix() const; const_iterator begin() const; const_iterator end() const; const_iterator cbegin() const; const_iterator cend() const; template<class OutIt> OutIt format(OutIt out, const char_type *fmt_first, const char_type *fmt_last, match_flag_type flags = format_default) const; template<class OutIt, class Traits1, class Alloc1> OutIt format(OutIt out, const basic_string<char_type, Traits1, Alloc1>& fmt, match_flag_type flags = format_default) const; template<class Traits1, class Alloc1> basic_string<char_type, Traits1, Alloc1> format( const basic_string<char_type, Traits1, Alloc1>& fmt, match_flag_type flags = format_default) const; string_type format(const char_type *fmt, match_flag_type flags = format_default) const; allocator_type get_allocator() const; void swap(const match_results& other) throw(); size_type size() const; size_type max_size() const; bool empty() const; bool ready() const; [added with C++11] typedef sub_match<BidIt> value_type; typedef const typename Alloc::const_reference const_reference; typedef const_reference reference; typedef T0 const_iterator; typedef const_iterator iterator; typedef typename iterator_traits<BidIt>::difference_type difference_type; typedef typename Alloc::size_type size_type; typedef Alloc allocator_type; typedef typename iterator_traits<BidIt>::value_type char_type; typedef basic_string<char_type> string_type; };
The template class describes an object that controls a non-modifiable
sequence of elements of type sub_match<BidIt>
generated by
a regular expression search. The member function
ready()
returns true
only if the object stores the result of a regular expression search.
Each element points to the subsequence that matched
the capture group corresponding to that element.
match_results::allocator_type
typedef Alloc allocator_type;
The typedef is a synonym for the template argument Alloc
.
match_results::begin
const_iterator begin() const;
The member function returns a random access iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).
match_results::cbegin
const_iterator cbegin() const;
The member function returns a random access iterator that points at the first element of the sequence (or just beyond the end of an empty sequence).
match_results::cend
const_iterator cend() const;
The member function returns an iterator that points just beyond the end of the sequence.
match_results::char_type
typedef typename iterator_traits<BidIt>::value_type char_type;
The typedef is a synonym for the type
iterator_traits<BidIt>::value_type
, which is the element
type of the character sequence that was searched.
match_results::const_iterator
typedef T0 const_iterator;
The typedef describes an object that can serve as a constant random-access iterator for the controlled sequence.
match_results::const_reference
typedef const typename Alloc::const_reference const_reference;
The typedef describes an object that can serve as a constant reference to an element of the controlled sequence.
match_results::difference_type
typedef typename iterator_traits<BidIt>::difference_type difference_type;
The typedef is a synonym for the type
iterator_traits<BidIt>::difference_type
; it describes an object
that can represent the difference between any two iterators that point at elements
of the controlled sequence.
match_results::empty
bool empty() const;
The member function returns true only if the regular expression search failed.
match_results::end
const_iterator end() const;
The member function returns an iterator that points just beyond the end of the sequence.
match_results::format
template<class OutIt> OutIt format(OutIt out, const char_type *fmt_first, const char_type *fmt_last, match_flag_type flags = format_default) const; template<class OutIt, class Traits1, class Alloc1> OutIt format(OutIt out, const basic_string<char_type, Traits1, Alloc1>& fmt, match_flag_type flags = format_default) const; template<class Traits1, class Alloc1> basic_string<char_type, Traits1, Alloc1> format( const basic_string<char_type, Traits1, Alloc1>& fmt, match_flag_type flags = format_default) const; string_type format(const char_type *fmt, match_flag_type flags = format_default) const;
Each member function generates formatted text
under the control of the format fmt
or [fmt_first, fmt_last)
. Each of the first two member functions
writes the formatted text to the sequence defined by its argument out
and returns out
. Each of the last two member functions
returns a string object holding a copy of the formatted text.
To generate formatted text, literal text in the format string is ordinarily copied to the target sequence. Each escape sequence in the format string is replaced by the text that it represents. The details of the copying and replacement are controlled by the format flags passed to the function.
match_results::get_allocator
allocator_type get_allocator() const;
The member function returns a copy of the allocator object used by
*this
to allocate its sub_match
objects.
match_results::iterator
typedef const_iterator iterator;
The type describes an object that can serve as a random-access iterator for the controlled sequence.
match_results::length
difference_type length(size_type sub = 0) const;
The member function returns (*this)[sub].length()
.
match_results::match_results
explicit match_results(const Alloc& alloc = Alloc()); match_results(const match_results& right); match_results(match_results&& right); [added with C++11]
The first constructor constructs a match_results
object that
holds no submatches. The second constructor constructs a match_results
object that is a copy of right
. The third constructor behaves the
same as the second, using an
rvalue reference.
match_results::max_size
size_type max_size() const;
The member function returns the length of the longest sequence that the object can control.
match_results::operator=
match_results& operator=(const match_results& right); match_results& operator=(match_results&& right) noexcept; [added with C++11]
The member operator replaces the sequence controlled by *this
with a copy of the sequence controlled by right
.
match_results::operator[]
const_reference operator[](size_type n) const;
The member function returns a reference to element n
of
the controlled sequence, or a reference to an empty sub_match
object
if size() <= n
or if
capture group
n
was not part of the match.
match_results::position
difference_type position(size_type sub = 0) const;
The member function returns
distance(prefix().first, (*this)[sub].first)
, that is, the
distance from the first character in the target sequence to the first character
in the submatch pointed to by element n
of the controlled
sequence.
match_results::prefix
const_reference prefix() const;
The member function returns a reference to an object of type
sub_match<BidIt>
that points to the character sequence that
begins at the start of the target sequence and ends at
(*this)[0].first
, that is, it points to the text that precedes
the matched subsequence.
match_results::ready
bool ready() const; [added with C++11]
The member function returns true only if the object stores the result of a regular expression search.
match_results::reference
typedef const_reference reference;
The type is a synonym for the type const_reference
.
match_results::size
size_type size() const;
The member function returns one more than the number of capture groups in the regular expression that was used for the search, or zero if no search has been made.
match_results::size_type
typedef typename Alloc::size_type size_type;
The type is a synonym for the type Alloc::size_type
.
match_results::str
string_type str(size_type sub = 0) const;
The member function returns string_type((*this)[sub])
.
match_results::string_type
typedef basic_string<char_type> string_type;
The type is a synonym for the type basic_string<char_type>
.
match_results::suffix
const_reference suffix() const;
The member function returns a reference to an object of type
sub_match<BidIt>
that points to the character sequence that
begins at (*this)[size() - 1].second
and ends at the end of the
target sequence, that is, it points to the text that follows the matched
subsequence.
match_results::swap
void swap(const match_results& right) throw();
The member function swaps the contents of *this
and
right
in constant time and does not throw exceptions.
match_results::value_type
typedef sub_match<BidIt> value_type;
The typedef is a synonym for the type sub_match<BidIt>
.
operator==
template<class BidIt> bool operator==(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator==( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator==(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt> bool operator==(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator==(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type *right); template<class BidIt> bool operator==(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator==(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); template<class BidIt, class Alloc> bool operator==(const match_results<BidIt, Alloc>& left, const match_results<BidIt, Alloc>& right);
Each template operator converts each of its arguments to a string type and returns the result of comparing the converted objects for equality.
When a template operator converts its arguments to a string type it uses the first of the following transformations that applies:
match_results
or sub_match
are converted by calling the str
member function;basic_string
are unchanged;basic_string
. Two match_results
compare equal only if:
!left.ready() && !right.ready()
, orleft.ready() && right.ready()
, andleft.empty() && right.empty()
, or!left.empty() && !right.empty()
, andleft.size() == right.sizey()
, andleft.prefix() && right.prefix()
, andleft.suffix() && right.suffix()
, andequal(left.begin(), left.end(), right.begin()
.operator!=
template<class BidIt> bool operator!=(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator!=( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator!=(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt> bool operator!=(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator!=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type *right); template<class BidIt> bool operator!=(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator!=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right); template<class BidIt, class Alloc> bool operator!=(const match_results<BidIt, Alloc>& left, const match_results<BidIt, Alloc>& right);
Each template operator returns !(left == right)
.
operator<
template<class BidIt> bool operator<(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt> bool operator<(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator<(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type *right); template<class BidIt> bool operator<(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator<(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right);
Each template operator
converts its arguments to a string type
and returns true only if the converted value of left
compares less than the converted value of right
.
operator<=
template<class BidIt> bool operator<=(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<=( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator<=(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt> bool operator<=(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator<=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type *right); template<class BidIt> bool operator<=(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator<=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right);
Each template operator returns !(right < left)
.
operator>
template<class BidIt> bool operator>(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt> bool operator>(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator>(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type *right); template<class BidIt> bool operator>(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator>(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right);
Each template operator returns right < left
.
operator>=
template<class BidIt> bool operator>=(const sub_match<BidIt>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>=( const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& left, const sub_match<BidIt>& right); template<class BidIt, class IOtraits, class Alloc> bool operator>=(const sub_match<BidIt>& left, const basic_string<typename iterator_traits<BidIt>::value_type, IOtraits, Alloc>& right); template<class BidIt> bool operator>=(const typename iterator_traits<BidIt>::value_type *left, const sub_match<BidIt>& right); template<class BidIt> bool operator>=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type *right); template<class BidIt> bool operator>=(const typename iterator_traits<BidIt>::value_type& left, const sub_match<BidIt>& right); template<class BidIt> bool operator>=(const sub_match<BidIt>& left, const typename iterator_traits<BidIt>::value_type& right);
Each template operator returns !(left < right)
.
operator<<
template<class Elem, class IOtraits, class Alloc, class BidIt> basic_ostream<Elem, IOtraits>& operator<<(basic_ostream<Elem, IOtraits>& os, const sub_match<BidIt>& right);
The template operator returns os << right.str()
.
regex
typedef basic_regex<char> regex;
The type describes a specialization of template class basic_regex for elements of type char.
regex_constants
namespace regex_constants { typedef T1 syntax_option_type; typedef T2 match_flag_type; typedef T3 error_type; }
The namespace regex_constants
within std
encapsulates several flag types and their associated flag values.
regex_constants::error_type
typedef T3 error_type; static const error_type error_badbrace, error_badrepeat, error_brace, error_brack, error_collate, error_complexity, error_ctype, error_escape, error_paren, error_range, error_space, error_stack, error_backref;
The type is an enumeration type that describes an object that can hold error flags. The distinct flag values are:
error_badbrace
-- the expression contained an invalid count in a { } expressionerror_badrepeat
-- a repeat expression (one of '*', '?', '+', '{' in most contexts) was not
preceded by an expressionerror_brace
-- the expression contained an unmatched '{' or '}'error_brack
-- the expression contained an unmatched '[' or ']'error_collate
-- the expression contained an invalid collating element nameerror_complexity
-- an attempted match failed because it was too complexerror_ctype
-- the expression contained an invalid character class nameerror_escape
-- the expression contained an invalid escape sequenceerror_paren
-- the expression contained an unmatched '(' or ')'error_range
-- the expression contained an invalid character range specifiererror_space
-- parsing a regular expression failed because there were not enough
resources availableerror_stack
-- an attempted match failed because there was not enough memory availableerror_backref
-- the expression contained an invalid back referenceregex_constants::match_flag_type
typedef T2 match_flag_type; static const match_flag_type match_any, match_default, match_not_bol, match_not_bow, match_continuous, match_not_eol, match_not_eow, match_not_null, match_prev_avail;
The type is a bitmask type that describes options to be used when matching a
text sequence against a regular expression and format flags to be used when
replacing text. Options can be combined with |
.
The match options are:
match_default
match_not_bol
-- do not treat the first position in the target sequence as the beginning
of a linematch_not_eol
-- do not treat the past-the-end position in the target sequence as the end
of a linematch_not_bow
-- do not treat the first position in the target sequence as the beginning
of a wordmatch_not_eow
-- do not treat the past-the-end position in the target sequence as the end
of a wordmatch_any
-- if more than one match is possible any match is acceptablematch_not_null
-- do not treat an empty subsequence as a matchmatch_continuous
-- do not search for matches other than at the beginning of the target sequencematch_prev_avail
-- --first
is a valid iterator; ignore match_not_bol
and match_not_bow
if setThe format flags are:
format_default
-- use ECMAScript format rulesformat_sed
-- use sed format rulesformat_no_copy
-- do not copy text that does not match the regular expressionformat_first_only
-- do not search for matches after the first oneregex_constants::syntax_option_type
typedef T1 syntax_option_type; static const syntax_option_type awk, basic, collate, ECMAScript, egrep, extended, grep, icase, nosubs, optimize;
The type is a bitmask type that describes language specifiers and syntax
modifiers to be used when compiling a regular expression. Options can be combined
with |
. No more than one language specifier should be used at a time.
The language specifiers are:
basic
-- compile as BREextended
-- compile as EREECMAScript
-- compile as ECMAScriptawk
-- compile as awkgrep
-- compile as grepegrep
-- compile as egrepThe syntax modifiers are:
icase
-- make matches case-insensitivenosubs
-- the implementation need not keep track of the contents of
capture groupsoptimize
-- the implementation should emphasize speed of matching rather than speed
of regular expression compilationcollate
-- make matches locale-sensitiveregex_error
class regex_error : public runtime_error { public: explicit regex_error(regex_constants::error_code error); regex_constants::error_code code() const; };
The class describes an exception object thrown to report an error
in the construction or use of a basic_regex
object.
regex_error::code
regex_constants::error_code code() const;
The member function returns the value that was passed to the object's constructor.
regex_error::regex_error
regex_error(regex_constants::error_code error);
The constructor constructs an object that holds the value error
.
regex_iterator
template<class BidIt, class Elem = iterator_traits<BidIt>::value_type, class RXtraits = regex_traits<Elem> > class regex_iterator { public: typedef basic_regex<Elem, RXtraits> regex_type; typedef match_results<BidIt> value_type; typedef forward_iterator_tag iterator_category; typedef ptrdiff_t difference_type; typedef const match_results<BidIt> *pointer; typedef const match_results<BidIt>& reference; regex_iterator(); regex_iterator(BidIt first, BidIt last, const regex_type& re, regex_constants::match_flag_type f = regex_constants::match_default); bool operator==(const regex_iterator& right); const bool operator!=(const regex_iterator& right); const const match_results<BidIt>& operator*(); const const match_results<BidIt> *operator->(); const regex_iterator& operator++(); regex_iterator& operator++(int); BidIt begin; // exposition only BidIt end; // exposition only regex_type *pregex; // exposition only regex_constants::match_flag_type flags; // exposition only match_results<BidIt> match; // exposition only };
The template class describes a constant forward iterator object. It extracts
objects of type match_results<BidIt>
by repeatedly applying
its regular expression object *pregex
to the character sequence
defined by the iterator range [begin, end)
.
regex_iterator::difference_type
typedef ptrdiff_t difference_type;
The type is a synonym for ptrdiff_t
.
regex_iterator::iterator_category
typedef forward_iterator_tag iterator_category;
The type is a synonym for forward_iterator_tag
.
regex_iterator::operator==
bool operator==(const regex_iterator& right);
The member function returns true if *this
and right
are both end-of-sequence iterators or if neither is an end-of-sequence iterator and
begin == right.begin
,
end == right.end
,
pregex == right.pregex
, and
flags == right.flags
.
Otherwise it returns false.
regex_iterator::operator!=
bool operator!=(const regex_iterator& right);
The member function returns !(*this == right)
.
regex_iterator::operator*
const match_results<BidIt>& operator*();
The member function returns the stored value match
.
regex_iterator::operator->
const match_results<BidIt> *operator->();
The member function returns the address of the stored value
match
.
regex_iterator::operator++
regex_iterator& operator++(); regex_iterator& operator++(int);
If the current match has no characters the first operator calls
regex_search(begin, end, match, *pregex, flags
| regex_constants::match_prev_avail | regex_constants::match_not_null)
;
otherwise it advances the stored value begin
to point to the first
character after the current match then calls regex_search(begin, end, match,
*pregex, flags | regex_constants::match_prev_avail)
. In either case,
if the search fails the operator sets the object to an end-of-sequence iterator.
The operator returns the object.
The second operator makes a copy of the object, increments the object, then returns the copy.
regex_iterator::pointer
typedef const match_results<BidIt> *pointer;
The type is a synonym for match_results<BidIt>*
, where
BidIt
is the template parameter.
regex_iterator::reference
typedef const match_results<BidIt>& reference;
The type is a synonym for match_results<BidIt>&
, where
BidIt
is the template parameter.
regex_iterator::regex_iterator
regex_iterator(); regex_iterator(BidIt first, BidIt last, const regex_type& re, regex_constants::match_flag_type f = regex_constants::match_default);
The first constructor constructs an end-of-sequence iterator.
The second constructor initializes
the stored value begin
with first
,
the stored value end
with last
,
the stored value pregex
with &re
, and
the stored value flags
with f
.
It then calls regex_search(begin, end, match, *pregex, flags)
.
If the search fails, the constructor sets the object to an end-of-sequence iterator.
regex_iterator::regex_type
typedef basic_regex<Elem, RXtraits> regex_type;
The typedef is a synonym for basic_regex<Elem, RXtraits>
.
regex_iterator::value_type
typedef match_results<BidIt> value_type;
The type is a synonym for match_results<BidIt>
, where
BidIt
is the template parameter.
regex_match
template<class BidIt, class Alloc, class Elem, class RXtraits, class Alloc2> bool regex_match(BidIt first, Bidit last, match_results<BidIt, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class BidIt, class Elem, class RXtraits, class Alloc2> bool regex_match(BidIt first, Bidit last, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class Elem, class Alloc, class RXtraits, class Alloc2> bool regex_match(const Elem *ptr, match_results<const Elem *, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class Elem, class RXtraits, class Alloc2> bool regex_match(const Elem *ptr, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits, class Alloc2> bool regex_match(const basic_string<Elem, IOtraits, IOalloc>& str, match_results<typename basic_string<Elem, IOtraits, IOalloc>::const_iterator, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Elem, class RXtraits, class Alloc2> bool regex_match(const basic_string<Elem, IOtraits, IOalloc>& str, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default);
Each template function returns true only if its
operand sequence exactly
matches its regular
expression argument re
. The functions that take a
match_results
object set its members to reflect whether the match
succeeded and if so what the various
capture groups
in the regular expression captured.
regex_replace
template<class OutIt, class BidIt, class RXtraits, class Elem, class Traits, class Alloc> OutIt regex_replace(OutIt out, BidIt first, BidIt last, const basic_regex<Elem, RXtraits>& re, const basic_string<Elem, Traits, Alloc>& fmt, match_flag_type flags = match_default); template<class OutIt, class BidIt, class RXtraits, class Elem> OutIt regex_replace(OutIt out, BidIt first, BidIt last, const basic_regex<Elem, RXtraits>& re, const Elem *fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem, class Traits1, class Alloc1, class Traits2, class Alloc2> basic_string<Elem, Traits1, Alloc1> regex_replace( const basic_string<Elem, Traits1, Alloc1>& str, const basic_regex<Elem, RXtraits>& re, const basic_string<Elem, Traits2, Alloc2>& fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem, class Traits1, class Alloc1> basic_string<Elem, Traits1, Alloc1> regex_replace( const basic_string<Elem, Traits1, Alloc1>& str, const basic_regex<Elem, RXtraits>& re, const Elem *fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem, class Traits2, class Alloc2> basic_string<Elem> regex_replace( const Elem *str, const basic_regex<Elem, RXtraits>& re, const basic_string<Elem, Traits2, Alloc2>& fmt, match_flag_type flags = match_default); template<class RXtraits, class Elem> basic_string<Elem> regex_replace( const Elem *str, const basic_regex<Elem, RXtraits>& re, const Elem *fmt, match_flag_type flags = match_default);
Each of the first two functions constructs
a regex_iterator object
iter(first, last, re, flags)
and uses it to split its input
range [first, last)
into a
series of subsequences
T0M0T1M1...TN-1MN-1TN
,
where Mn
is the nth
match detected by
the iterator. If no matches are found, T0
is the entire
input range and N
is zero. If
(flags & format_first_only) != 0
only the first match
is used, T1
is all of the input text that follows the
match, and N
is 1.
For each i
in the range [0, N)
, if
(flags & format_no_copy) == 0
it copies the text in the range
Ti
to the iterator out
. It then calls
m.format(out, fmt, flags)
, where m
is the
match_results
object returned by the iterator object iter
for the subsequence Mi
. Finally, if
(flags & format_no_copy) == 0
it copies the text in the range
TN
to the iterator out
. The function returns
out
.
Each of the remaining four functions constructs
a local variable result
of the return type and calls
regex_replace(back_inserter(result), str.begin(), str.end(), re, fmt, flags)
.
It returns result
.
regex_search
template<class BidIt, class Alloc, class Elem, class RXtraits, class Alloc2> bool regex_search(BidIt first, Bidit last, match_results<BidIt, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class BidIt, class Elem, class RXtraits, class Alloc2> bool regex_search(BidIt first, Bidit last, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class Elem, class Alloc, class RXtraits, class Alloc2> bool regex_search(const Elem *ptr, match_results<const Elem*, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class Elem, class RXtraits, class Alloc2> bool regex_search(const Elem *ptr, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Alloc, class Elem, class RXtraits, class Alloc2> bool regex_search(const basic_string<Elem, IOtraits, IOalloc>& str, match_results<typename basic_string<Elem, IOtraits, IOalloc>::const_iterator, Alloc>& match, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default); template<class IOtraits, class IOalloc, class Elem, class RXtraits, class Alloc2> bool regex_search(const basic_string<Elem, IOtraits, IOalloc>& str, const basic_regex<Elem, RXtraits, Alloc2>& re, match_flag_type flags = match_default);
Each template function returns true only if a
search for its regular expression
argument re
in its
operand sequence succeeds. The functions that
take a match_results
object set its members to reflect whether
the search succeeded and if so what the various
capture groups
in the regular expression captured.
regex_token_iterator
template<class BidIt, class Elem = iterator_traits<BidIt>::value_type, class RXtraits = regex_traits<Elem> > class regex_token_iterator { public: typedef basic_regex<Elem, RXtraits> regex_type; typedef sub_match<BidIt> value_type; typedef forward_iterator_tag iterator_category; typedef ptrdiff_t difference_type; typedef const sub_match<BidIt> *pointer; typedef const sub_match<BidIt>& reference; regex_token_iterator(); regex_token_iterator(BidIt first, BidIt last, const regex_type& re, int submatch = 0, regex_constants::match_flag_type f = regex_constants::match_default); regex_token_iterator(BidIt first, BidIt last, const regex_type& re, const vector<int> submatches, regex_constants::match_flag_type f = regex_constants::match_default); template<size_t N> regex_token_iterator(BidIt first, BidIt last, const regex_type& re, const int (&submatches)[N], regex_constants::match_flag_type f = regex_constants::match_default); regex_token_iterator(BidIt first, BidIt last, const regex_type& re, initializer_list<int> init, regex_constants::match_flag_type f = regex_constants::match_default); bool operator==(const regex_token_iterator& right); const bool operator!=(const regex_token_iterator& right); const const basic_string<Elem>& operator*(); const const basic_string<Elem> *operator->(); const regex_token_iterator& operator++(); regex_token_iterator& operator++(int); private: regex_iterator<BidIt, Elem, RXtraits> it; // exposition only vector<int> subs; // exposition only int pos; // exposition only };
The template class describes a constant forward iterator object.
Conceptually, it holds a regex_iterator
object that it uses to
search for regular expression matches in a character sequence. It extracts
objects of type sub_match<BidIt>
representing the
submatches identified by the index values in the stored vector
subs
for each regular expression match.
An index value of -1 designates the
character sequence beginning immediately after the end of the previous regular
expression match, or beginning at the start of the character sequence if there
was no previous regular expression match, and extending to but not including
the first character of the current regular expression match, or to the end
of the character sequence if there is no current match. Any other index
value idx
designates the contents of the capture group held in
it.match[idx]
.
regex_token_iterator::difference_type
typedef ptrdiff_t difference_type;
The type is a synonym for ptrdiff_t
.
regex_token_iterator::iterator_category
typedef forward_iterator_tag iterator_category;
The type is a synonym for forward_iterator_tag
.
regex_token_iterator::operator==
bool operator==(const regex_token_iterator& right);
The member function returns it == right.it &&
subs == right.subs && pos == right.pos
.
regex_token_iterator::operator!=
bool operator!=(const regex_token_iterator& right);
The member function returns !(*this == right)
.
regex_token_iterator::operator*
const sub_match<BidIt>& operator*();
The member function returns a sub_match<BidIt>
object
representing the capture group identified by the
index value subs[pos]
.
regex_token_iterator::operator->
const sub_match<BidIt> *operator->();
The member function returns a pointer to a
sub_match<BidIt>
object representing the capture group
identified by the index value
subs[pos]
.
regex_token_iterator::operator++
regex_token_iterator& operator++(); regex_token_iterator& operator++(int);
If the stored iterator it
is an end-of-sequence iterator
the first operator sets the stored value pos
to the value of
subs.size()
(thus making an end-of-sequence iterator). Otherwise
the operator increments the stored value pos
; if the result
is equal to the value subs.size()
it sets the stored value
pos
to zero and increments the stored iterator it
. If
incrementing the stored iterator leaves it unequal to an end-of-sequence
iterator the operator does nothing further. Otherwise, if the end of the
preceding match was at the end of the character sequence the operator
sets the stored value of pos
to subs.size()
.
Otherwise, the operator repeatedly increments the stored value pos
until pos == subs.size()
or subs[pos] == -1
(thus
ensuring that the next dereference of the iterator will return the tail
of the character sequence if one of the
index values is -1). In all cases the operator
returns the object.
The second operator makes a copy of the object, increments the object, then returns the copy.
regex_token_iterator::pointer
typedef const sub_match<BidIt> *pointer;
The type is a synonym for sub_match<BidIt>*
, where
BidIt
is the template parameter.
regex_token_iterator::reference
typedef const sub_match<BidIt>& reference;
The type is a synonym for sub_match<BidIt>&
, where
BidIt
is the template parameter.
regex_token_iterator::regex_token_iterator
regex_token_iterator(); regex_token_iterator(BidIt first, BidIt last, const regex_type& re, int submatch = 0, regex_constants::match_flag_type f = regex_constants::match_default); regex_token_iterator(BidIt first, BidIt last, const regex_type& re, const vector<int> submatches, regex_constants::match_flag_type f = regex_constants::match_default); template<size_t N> regex_token_iterator(BidIt first, BidIt last, const regex_type& re, const int (&submatches)[N], regex_constants::match_flag_type f = regex_constants::match_default); regex_token_iterator(BidIt first, BidIt last, const regex_type& re, initializer_list<int> init, regex_constants::match_flag_type f = regex_constants::match_default);
The first constructor constructs an end-of-sequence iterator.
The second constructor constructs an object whose stored iterator
it
is initialized to
regex_iterator<BidIt, Elem, RXtraits>(first, last, re, f)
,
whose stored vector subs
holds exactly one integer, with value
submatch
, and whose stored value pos
is zero. Note: the
resulting object extracts the submatch identified by the
index value submatch
for
each successful regular expression match.
The third constructor constructs an object whose stored iterator
it
is initialized to
regex_iterator<BidIt, Elem, RXtraits>(first, last, re, f)
,
whose stored vector subs
holds a copy of the constructor argument
submatches
, and whose stored value pos
is zero.
The fourth constructor constructs an object whose stored iterator
it
is initialized to
regex_iterator<BidIt, Elem, RXtraits>(first, last, re, f)
,
whose stored vector subs
holds the N
values pointed to
by the constructor argument submatches
, and whose stored value
pos
is zero.
The fifth constructor constructs an object whose stored iterator
it
is initialized to
regex_iterator<BidIt, Elem, RXtraits>(first, last, re, f)
,
whose stored vector subs
holds the sequence of elements from
an object of class
initializer_list<int>
,
and whose stored value pos
is zero.
regex_token_iterator::regex_type
typedef basic_regex<Elem, RXtraits> regex_type;
The typedef is a synonym for basic_regex<Elem, RXtraits>
.
regex_token_iterator::value_type
typedef sub_match<BidIt> value_type;
The type is a synonym for sub_match<BidIt>
, where
BidIt
is the template parameter.
regex_traits
template<class Elem> struct regex_traits { regex_traits(); static size_type length(const char_type *str); char_type translate(char_type ch) const; char_type translate_nocase(char_type ch) const; template<class FwdIt> string_type transform(FwdIt first, FwdIt last) const; template<class FwdIt> string_type transform_primary(FwdIt first, FwdIt last) const; template<class FwdIt> char_class_type lookup_classname(FwdIt first, FwdIt last, bool caseless) const; template<class FwdIt> string_type lookup_collatename(FwdIt first, FwdIt last) const; bool isctype(char_type ch, char_class_type cls) const; int value(Elem ch, int base) const; locale_type imbue(locale_type loc); locale_type getloc() const; typedef Elem char_type; typedef T6 size_type; typedef basic_string<Elem> string_type; typedef T7 locale_type; typedef T8 char_class_type; };
The template class describes various regular expression traits for type Elem. The template class basic_regex uses this information to manipulate elements of type Elem.
Each regex_traits
object holds an object of type
regex_traits::locale
which is used by some of its member functions.
The default locale is a copy of
regex_traits::locale()
. The member function imbue
replaces the locale object, and the member function getloc
returns
a copy of the locale object.
regex_traits::char_class_type
typedef T8 char_class_type;
The type is a synonym for an unspecified type that designates character
classes. Values of this type can be combined using the |
operator
to designate character classes that are the union of the classes designated by
the operands.
regex_traits::char_type
typedef Elem char_type;
The typedef is a synonym for the template argument Elem
.
regex_traits::getloc
locale_type getloc() const;
The member function returns the stored locale
object.
regex_traits::imbue
locale_type imbue(locale_type loc);
The member function copies loc
to the stored locale
object and returns a copy of the previous value of the stored
locale
object.
regex_traits::isctype
bool isctype(char_type ch, char_class_type cls) const;
The member function returns true only if the character ch
is
in the character class designated by cls
.
regex_traits::length
static size_type length(const char_type *str);
The static member function returns
char_traits<char_type>::length(str)
.
regex_traits::locale_type
typedef T7 locale_type;
The typedef is a synonym for a type that encapsulates locales. In the
specializations regex_traits<char>
and
regex_traits<wchar_t>
it is a synonym for
locale
.
regex_traits::lookup_classname
template<class FwdIt> char_class_type lookup_classname(FwdIt first, FwdIt last, bool caseless) const;
The member function returns a value that designates the character class
named by the character sequence pointed to by its arguments.
If caseless
, a character class that includes either lower case
or upper case is extended to include both cases.
The specialization regex_traits<char>
recognizes the names
"d"
,
"s"
,
"w"
,
"alnum"
,
"alpha"
,
"blank"
,
"cntrl"
,
"digit"
,
"graph"
,
"lower"
,
"print"
,
"punct"
,
"space"
,
"upper"
, and
"xdigit"
,
all without regard to case.
The specialization regex_traits<wchar_t>
recognizes the names
L"d"
,
L"s"
,
L"w"
,
L"alnum"
,
L"alpha"
,
L"blank"
,
L"cntrl"
,
L"digit"
,
L"graph"
,
L"lower"
,
L"print"
,
L"punct"
,
L"space"
,
L"upper"
, and
L"xdigit"
,
all without regard to case.
regex_traits::lookup_collatename
template<class FwdIt> string_type lookup_collatename(FwdIt first, FwdIt last) const;
The member function returns a string object containing
the collating element corresponding to the sequence
[first, last)
, or an empty string if the sequence is
not a valid collating element.
regex_traits::regex_traits
regex_traits();
The constructor constructs an object whose stored locale
object
is initialized to the default locale.
regex_traits::size_type
typedef T6 size_type;
The typedef is a synonym for an unsigned integral type. In the
specializations regex_traits<char>
and
regex_traits<wchar_t>
it is a synonym for
size_t
.
The typedef is a synonym for size_t
.
regex_traits::string_type
typedef basic_string<Elem> string_type;
The typedef is a synonym for basic_string<Elem>
.
regex_traits::value
int value(Elem ch, int radix) const;
The member function returns the value represented by the character ch
in the base radix
, or -1 if ch
is not a valid digit
in the base radix
. The function will only be called with
a radix
argument of 8, 10, or 16.
regex_traits::transform
template<class FwdIt> string_type transform(FwdIt first, FwdIt last) const;
The member function returns a string that it generates by using a
transformation rule that depends on the stored locale
object. For
two character sequences designated by the iterator ranges [first1, last1)
and
[first2, last2)
,
transform(first1, last1) < transform(first2, last2)
if the character sequence designated by the iterator range [first1, last1)
sorts before the character sequence designated by the iterator range
[first2, last2)
.
regex_traits::transform_primary
template<class FwdIt> string_type transform_primary(FwdIt first, FwdIt last) const;
The member function returns a string that it generates by using a
transformation rule that depends on the stored locale
object. For
two character sequences designated by the iterator ranges [first1, last1)
and
[first2, last2)
,
transform_primary(first1, last1) < transform_primary(first2, last2)
if the character sequence designated by the iterator range [first1, last1)
sorts before the character sequence designated by the iterator range
[first2, last2)
without regard for case or accents.
regex_traits::translate
char_type translate(char_type ch) const;
The member function returns a character that it generates by using a
transformation rule that depends on the stored locale
object. For
two char_type
objects ch1
and ch2
,
translate(ch1) == translate(ch2)
only if
ch1
and ch2
should match when
one occurs in the regular expression definition and the other occurs at a
corresponding position in the target sequence for a
locale-sensitive match.
regex_traits::translate_nocase
char_type translate_nocase(char_type ch) const;
The member function returns a character that it generates by using a
transformation rule that depends on the stored locale
object. For
two char_type
objects ch1
and ch2
,
translate_nocase(ch1) == translate_nocase(ch2)
only if
ch1
and ch2
should match when
one occurs in the regular expression definition and the other occurs at a
corresponding position in the target sequence for a
case-insensitive match.
regex_traits<char>
template <> class regex_traits<char>
The class is an explicit specialization of template class regex_traits for elements of type char (so that it can take advantage of library functions that manipulate objects of this type).
regex_traits<wchar_t>
template <> class regex_traits<wchar_t>
The class is an explicit specialization of template class regex_traits for elements of type wchar_t (so that it can take advantage of library functions that manipulate objects of this type).
smatch
typedef match_results<string::const_iterator> smatch;
The type describes a specialization of template class match_results for iterators of type string::const_iterator.
sregex_iterator
typedef regex_iterator<string::const_iterator> sregex_iterator;
The type describes a specialization of template class regex_iterator for iterators of type string::const_iterator.
sregex_token_iterator
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
The type describes a specialization of template class regex_token_iterator for iterators of type string::const_iterator.
ssub_match
typedef sub_match<string::const_iterator> ssub_match;
The type describes a specialization of template class sub_match for iterators of type string::const_iterator.
sub_match
template<class BidIt> class sub_match : public pair<BidIt, BidIt> { public: typedef typename iterator_traits<BidIt>::value_type value_type; typedef typename iterator_traits<BidIt>::difference_type difference_type; typedef BidIt iterator; typedef basic_string<value_type> string_type; constexpr sub_match(); int compare(const sub_match& right) const; int compare(const string_type& right) const; int compare(const value_type *right) const; difference_type length() const; operator string_type() const; string_type str() const; bool matched; };
The template class describes an object that designates a sequence of characters that matched a capture group in a call to regex_match or to regex_search. Objects of type match_results hold an array of these objects, one for each capture group in the regular expression that was used in the search.
If the capture group was not matched the object's data member
matched
holds false, and the two iterators first
and
second
(inherited from the base pair
) are equal.
If the capture group was matched, matched
holds true, the
iterator first
points to the first character in the target sequence
that matched the capture group, and the iterator second
points one
position past the last character in the target sequence that matched the
capture group. Note that for a zero-length match the
member matched
holds true, the two iterators will be equal, and
both will point to the position of the match.
A zero-length match can occur when a capture group consists solely of an assertion, or of a repetition that allows zero repeats. For example:
sub_match
object corresponding to capture group 0 holds iterators
that both point to the first character in the sequence.sub_match
object corresponding to capture group 1 holds iterators
that both point to the second character in the sequence.sub_match::compare
int compare(const sub_match& right) const; int compare(const string_type& right) const; int compare(const value_type *right) const;
The first member function compares the matched sequence
[first, second)
to the matched sequence
[right.first, right.second)
.
The second member function compares the matched sequence
[first, second)
to the character sequence
[right.begin(), right.end())
.
The third member function compares the matched sequence
[first, second)
to the character sequence
[right, right +
char_traits<value_type>::length(right))
.
Each function returns:
char_traits<value_type>::compare
), or if the two have
a common prefix but the target sequence is longersub_match::difference_type
typedef typename iterator_traits<BidIt>::difference_type difference_type;
The typedef is a synonym for iterator_traits<BidIt>::difference_type
.
sub_match::iterator
typedef BidIt iterator;
The typedef is a synonym for the template type argument Bidit
.
sub_match::length
difference_type length() const;
The member function returns the length of the matched sequence, or zero if there was no matched sequence.
sub_match::matched
bool matched;
The member holds true
only if the capture group associated with
*this
was part of the regular expression match.
sub_match::operator string_type
operator string_type() const;
The member operator returns str()
.
sub_match::str
string_type str() const;
The member function returns
string_type(first, second)
.
sub_match::string_type
typedef basic_string<value_type> string_type;
The typedef is a synonym for basic_string<value_type>
.
sub_match::sub_match
constexpr sub_match();
The default constructor value initializes its base class, and stores
false
in
matched
.
sub_match::value_type
typedef typename iterator_traits<BidIt>::value_type value_type;
The typedef is a synonym for iterator_traits<BidIt>::value_type
.
swap
template<class Elem, class RXtraits> void swap(basic_regex<Elem, RXtraits, Alloc>& left, basic_regex<Elem, RXtraits>& right) throw(); template<class Elem, class IOtraits, class BidIt, class Alloc> void swap(match_results<BidIt, Alloc>& left, match_results<BidIt, Alloc>& right) throw();
The template functions swap the contents of their respective arguments in constant time and do not throw exceptions.
wcmatch
typedef match_results<const wchar_t *> wcmatch;
The type describes a specialization of template class match_results for iterators of type const wchar_t*.
wcregex_iterator
typedef regex_iterator<const wchar_t*> wcregex_iterator;
The type describes a specialization of template class regex_iterator for iterators of type const wchar_t*.
wcregex_token_iterator
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
The type describes a specialization of template class regex_token_iterator for iterators of type const wchar_t*.
wcsub_match
typedef sub_match<const wchar_t*> wcsub_match;
The type describes a specialization of template class sub_match for iterators of type const wchar_t*.
wsmatch
typedef match_results<wstring::const_iterator> wsmatch;
The type describes a specialization of template class match_results for iterators of type wstring::const_iterator.
wsregex_iterator
typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
The type describes a specialization of template class regex_iterator for iterators of type wstring::const_iterator.
wsregex_token_iterator
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
The type describes a specialization of template class regex_token_iterator for iterators of type wstring::const_iterator.
wssub_match
typedef sub_match<wstring::const_iterator> wssub_match;
The type describes a specialization of template class sub_match for iterators of type wstring::const_iterator.
wregex
typedef basic_regex<wchar_t> wregex;
The type describes a specialization of template class basic_regex for elements of type wchar_t.
See also the Table of Contents and the Index.
Copyright © 1992-2013 by Dinkumware, Ltd. All rights reserved.