std::basic_regex - Man Page

A regular expression.

Synopsis

#include <regex>

Public Types

typedef regex_constants::syntax_option_type flag_type
typedef traits_type::locale_type locale_type
typedef traits_type::string_type string_type
typedef _Rx_traits traits_type
typedef _Ch_type value_type

Public Member Functions

basic_regex () noexcept
template<typename _FwdIter > basic_regex (_FwdIter __first, _FwdIter __last, flag_type __f=ECMAScript)
Constructs a basic regular expression from the range [first, last) interpreted according to the flags in f.
basic_regex (basic_regex &&__rhs) noexcept=default
Move-constructs a basic regular expression.
basic_regex (const _Ch_type *__p, flag_type __f=ECMAScript)
Constructs a basic regular expression from the sequence [__p, __p + char_traits<_Ch_type>::length(__p)) interpreted according to the flags in __f.
basic_regex (const _Ch_type *__p, std::size_t __len, flag_type __f=ECMAScript)
Constructs a basic regular expression from the sequence [p, p + len) interpreted according to the flags in f.
basic_regex (const basic_regex &__rhs)=default
Copy-constructs a basic regular expression.
template<typename _Ch_traits , typename _Ch_alloc > basic_regex (const std::basic_string< _Ch_type, _Ch_traits, _Ch_alloc > &__s, flag_type __f=ECMAScript)
Constructs a basic regular expression from the string s interpreted according to the flags in f.
basic_regex (initializer_list< _Ch_type > __l, flag_type __f=ECMAScript)
Constructs a basic regular expression from an initializer list.
~basic_regex ()
Destroys a basic regular expression.
template<typename _InputIterator > basic_regex & assign (_InputIterator __first, _InputIterator __last, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object.
basic_regex & assign (basic_regex &&__rhs) noexcept
Move-assigns one regular expression to another.
basic_regex & assign (const _Ch_type *__p, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object from a C-style null-terminated string containing a regular expression pattern.
basic_regex & assign (const _Ch_type *__p, size_t __len, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object from a C-style string containing a regular expression pattern.
basic_regex & assign (const basic_regex &__rhs) noexcept
Assigns one regular expression to another.
template<typename _Ch_traits , typename _Alloc > basic_regex & assign (const basic_string< _Ch_type, _Ch_traits, _Alloc > &__s, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object from a string containing a regular expression pattern.
basic_regex & assign (initializer_list< _Ch_type > __l, flag_type __flags=ECMAScript)
Assigns a new regular expression to a regex object.
flag_type flags () const noexcept
Gets the flags used to construct the regular expression or in the last call to assign().
locale_type getloc () const noexcept
Gets the locale currently imbued in the regular expression object.
locale_type imbue (locale_type __loc)
Imbues the regular expression object with the given locale.
unsigned int mark_count () const noexcept
Gets the number of marked subexpressions within the regular expression.
basic_regex & operator= (basic_regex &&)=default
Move-assigns one regular expression to another.
basic_regex & operator= (const _Ch_type *__p)
Replaces a regular expression with a new one constructed from a C-style null-terminated string.
basic_regex & operator= (const basic_regex &)=default
Assigns one regular expression to another.
template<typename _Ch_traits , typename _Alloc > basic_regex & operator= (const basic_string< _Ch_type, _Ch_traits, _Alloc > &__s)
Replaces a regular expression with a new one constructed from a string.
basic_regex & operator= (initializer_list< _Ch_type > __l)
Replaces a regular expression with a new one constructed from an initializer list.
void swap (basic_regex &__rhs) noexcept
Swaps the contents of two regular expression objects.

Static Public Attributes

Constants
std [28.8.1](1)

static constexpr flag_type icase
static constexpr flag_type nosubs
static constexpr flag_type optimize
static constexpr flag_type collate
static constexpr flag_type ECMAScript
static constexpr flag_type basic
static constexpr flag_type extended
static constexpr flag_type awk
static constexpr flag_type grep
static constexpr flag_type egrep
static constexpr flag_type multiline

Friends

template<typename _Bp , typename _Ap , typename _Cp , typename _Rp > bool __detail::__regex_algo_impl (_Bp, _Bp, match_results< _Bp, _Ap > &, const basic_regex< _Cp, _Rp > &, regex_constants::match_flag_type, __detail::_RegexExecutorPolicy, bool)
template<typename , typename , typename , bool > class __detail::_Executor

Detailed Description

template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>>

class std::basic_regex< _Ch_type, _Rx_traits >"A regular expression.

Specializations of this class template represent regular expressions constructed from sequences of character type _Ch_type. Use the std::regex typedef for std::basic_regex<char>.

A character sequence passed to the constructor will be parsed according to the chosen grammar, and used to create a state machine representing the regular expression. The regex object can then be passed to algorithms such as std::regex_match to match sequences of characters.

The syntax_option_type flag passed to the constructor selects from one of the supported regular expression grammars. The default is ECMAScript and the others are basic, extended, awk, grep, and egrep, which are variations on POSIX regular expressions.

Since

C++11

Definition at line 418 of file regex.h.

Member Typedef Documentation

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> typedef regex_constants::syntax_option_type std::basic_regex< _Ch_type, _Rx_traits >::flag_type

Definition at line 428 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> typedef traits_type::locale_type std::basic_regex< _Ch_type, _Rx_traits >::locale_type

Definition at line 429 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> typedef traits_type::string_type std::basic_regex< _Ch_type, _Rx_traits >::string_type

Definition at line 427 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> typedef _Rx_traits std::basic_regex< _Ch_type, _Rx_traits >::traits_type

Definition at line 426 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> typedef _Ch_type std::basic_regex< _Ch_type, _Rx_traits >::value_type

Definition at line 425 of file regex.h.

Constructor & Destructor Documentation

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> std::basic_regex< _Ch_type, _Rx_traits >::basic_regex () [inline], [noexcept]

Constructs a basic regular expression that does not match any character sequence.

Definition at line 456 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> std::basic_regex< _Ch_type, _Rx_traits >::basic_regex (const _Ch_type * __p, flag_type __f = ECMAScript) [inline], [explicit]

Constructs a basic regular expression from the sequence [__p, __p + char_traits<_Ch_type>::length(__p)) interpreted according to the flags in __f.

Parameters

__p A pointer to the start of a C-style null-terminated string containing a regular expression.
__f Flags indicating the syntax rules and options.

Exceptions

regex_error if __p is not a valid regular expression.

Definition at line 472 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> std::basic_regex< _Ch_type, _Rx_traits >::basic_regex (const _Ch_type * __p, std::size_t __len, flag_type __f = ECMAScript) [inline]

Constructs a basic regular expression from the sequence [p, p + len) interpreted according to the flags in f.

Parameters

__p A pointer to the start of a string containing a regular expression.
__len The length of the string containing the regular expression.
__f Flags indicating the syntax rules and options.

Exceptions

regex_error if __p is not a valid regular expression.

Definition at line 487 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> std::basic_regex< _Ch_type, _Rx_traits >::basic_regex (const basic_regex< _Ch_type, _Rx_traits > & __rhs) [default]

Copy-constructs a basic regular expression.

Parameters

__rhs A regex object.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> std::basic_regex< _Ch_type, _Rx_traits >::basic_regex (basic_regex< _Ch_type, _Rx_traits > && __rhs) [default], [noexcept]

Move-constructs a basic regular expression.

Parameters

__rhs A regex object.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> template<typename _Ch_traits , typename _Ch_alloc > std::basic_regex< _Ch_type, _Rx_traits >::basic_regex (const std::basic_string< _Ch_type, _Ch_traits, _Ch_alloc > & __s, flag_type __f = ECMAScript) [inline], [explicit]

Constructs a basic regular expression from the string s interpreted according to the flags in f.

Parameters

__s A string containing a regular expression.
__f Flags indicating the syntax rules and options.

Exceptions

regex_error if __s is not a valid regular expression.

Definition at line 519 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> template<typename _FwdIter > std::basic_regex< _Ch_type, _Rx_traits >::basic_regex (_FwdIter __first, _FwdIter __last, flag_type __f = ECMAScript) [inline]

Constructs a basic regular expression from the range [first, last) interpreted according to the flags in f.

Parameters

__first The start of a range containing a valid regular expression.
__last The end of a range containing a valid regular expression.
__f The format flags of the regular expression.

Exceptions

regex_error if [__first, __last) is not a valid regular expression.

Definition at line 538 of file regex.h.

References std::basic_regex< _Ch_type, _Rx_traits >::assign().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> std::basic_regex< _Ch_type, _Rx_traits >::basic_regex (initializer_list< _Ch_type > __l, flag_type __f = ECMAScript) [inline]

Constructs a basic regular expression from an initializer list.

Parameters

__l The initializer list.
__f The format flags of the regular expression.

Exceptions

regex_error if __l is not a valid regular expression.

Definition at line 550 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> std::basic_regex< _Ch_type, _Rx_traits >::~basic_regex () [inline]

Destroys a basic regular expression.

Definition at line 556 of file regex.h.

Member Function Documentation

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> template<typename _InputIterator > basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::assign (_InputIterator __first, _InputIterator __last, flag_type __flags = ECMAScript) [inline]

Assigns a new regular expression to a regex object.

Parameters

__first The start of a range containing a valid regular expression.
__last The end of a range containing a valid regular expression.
__flags Syntax option flags.

Exceptions

regex_error if p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, the object remains unchanged.

Definition at line 701 of file regex.h.

References std::basic_regex< _Ch_type, _Rx_traits >::assign().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::assign (basic_regex< _Ch_type, _Rx_traits > && __rhs) [inline], [noexcept]

Move-assigns one regular expression to another.

Parameters

__rhs Another regular expression object.

Definition at line 621 of file regex.h.

References std::move().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::assign (const _Ch_type * __p, flag_type __flags = ECMAScript) [inline]

Assigns a new regular expression to a regex object from a C-style null-terminated string containing a regular expression pattern.

Parameters

__p A pointer to a C-style null-terminated string containing a regular expression pattern.
__flags Syntax option flags.

Exceptions

regex_error if __p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains unchanged.

Definition at line 638 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::assign (const _Ch_type * __p, size_t __len, flag_type __flags = ECMAScript) [inline]

Assigns a new regular expression to a regex object from a C-style string containing a regular expression pattern.

Parameters

__p A pointer to a C-style string containing a regular expression pattern.
__len The length of the regular expression pattern string.
__flags Syntax option flags.

Exceptions

regex_error if p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains unchanged.

Definition at line 660 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::assign (const basic_regex< _Ch_type, _Rx_traits > & __rhs) [inline], [noexcept]

Assigns one regular expression to another.

Parameters

__rhs Another regular expression object.

Definition at line 612 of file regex.h.

Referenced by std::basic_regex< _Ch_type, _Rx_traits >::basic_regex(), std::basic_regex< _Ch_type, _Rx_traits >::assign(), and std::basic_regex< _Ch_type, _Rx_traits >::operator=().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> template<typename _Ch_traits , typename _Alloc > basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::assign (const basic_string< _Ch_type, _Ch_traits, _Alloc > & __s, flag_type __flags = ECMAScript) [inline]

Assigns a new regular expression to a regex object from a string containing a regular expression pattern.

Parameters

__s A string containing a regular expression pattern.
__flags Syntax option flags.

Exceptions

regex_error if __s does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains unchanged.

Definition at line 679 of file regex.h.

References std::basic_string< _CharT, _Traits, _Alloc >::data(), and std::basic_string< _CharT, _Traits, _Alloc >::size().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::assign (initializer_list< _Ch_type > __l, flag_type __flags = ECMAScript) [inline]

Assigns a new regular expression to a regex object.

Parameters

__l An initializer list representing a regular expression.
__flags Syntax option flags.

Exceptions

regex_error if __l does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, the object remains unchanged.

Definition at line 733 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> flag_type std::basic_regex< _Ch_type, _Rx_traits >::flags () const [inline], [noexcept]

Gets the flags used to construct the regular expression or in the last call to assign().

Definition at line 757 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> locale_type std::basic_regex< _Ch_type, _Rx_traits >::getloc () const [inline], [noexcept]

Gets the locale currently imbued in the regular expression object.

Definition at line 779 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> locale_type std::basic_regex< _Ch_type, _Rx_traits >::imbue (locale_type __loc) [inline]

Imbues the regular expression object with the given locale.

Parameters

__loc A locale.

Definition at line 767 of file regex.h.

References std::swap().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> unsigned int std::basic_regex< _Ch_type, _Rx_traits >::mark_count () const [inline], [noexcept]

Gets the number of marked subexpressions within the regular expression.

Definition at line 745 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::operator= (basic_regex< _Ch_type, _Rx_traits > &&) [default]

Move-assigns one regular expression to another.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::operator= (const _Ch_type * __p) [inline]

Replaces a regular expression with a new one constructed from a C-style null-terminated string.

Parameters

__p A pointer to the start of a null-terminated C-style string containing a regular expression.

Definition at line 579 of file regex.h.

References std::basic_regex< _Ch_type, _Rx_traits >::assign().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::operator= (const basic_regex< _Ch_type, _Rx_traits > &) [default]

Assigns one regular expression to another.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> template<typename _Ch_traits , typename _Alloc > basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::operator= (const basic_string< _Ch_type, _Ch_traits, _Alloc > & __s) [inline]

Replaces a regular expression with a new one constructed from a string.

Parameters

__s A pointer to a string containing a regular expression.

Definition at line 602 of file regex.h.

References std::basic_regex< _Ch_type, _Rx_traits >::assign().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> basic_regex & std::basic_regex< _Ch_type, _Rx_traits >::operator= (initializer_list< _Ch_type > __l) [inline]

Replaces a regular expression with a new one constructed from an initializer list.

Parameters

__l The initializer list.

Exceptions

regex_error if __l is not a valid regular expression.

Definition at line 591 of file regex.h.

References std::basic_regex< _Ch_type, _Rx_traits >::assign().

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> void std::basic_regex< _Ch_type, _Rx_traits >::swap (basic_regex< _Ch_type, _Rx_traits > & __rhs) [inline], [noexcept]

Swaps the contents of two regular expression objects.

Parameters

__rhs Another regular expression object.

Definition at line 789 of file regex.h.

References std::swap().

Member Data Documentation

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::awk [static], [constexpr]

Definition at line 443 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::basic [static], [constexpr]

Definition at line 441 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::collate [static], [constexpr]

Definition at line 439 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::ECMAScript [static], [constexpr]

Definition at line 440 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::egrep [static], [constexpr]

Definition at line 445 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::extended [static], [constexpr]

Definition at line 442 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::grep [static], [constexpr]

Definition at line 444 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::icase [static], [constexpr]

Definition at line 436 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::multiline [static], [constexpr]

Definition at line 447 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::nosubs [static], [constexpr]

Definition at line 437 of file regex.h.

template<typename _Ch_type , typename _Rx_traits  = regex_traits<_Ch_type>> constexpr flag_type std::basic_regex< _Ch_type, _Rx_traits >::optimize [static], [constexpr]

Definition at line 438 of file regex.h.

Author

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

Info

Thu Jan 19 2023 libstdc++