STD::BASIC_REGEX(3cxx)
β¨ std::basic_regex< _Ch_type, _Rx_traits > β¨
okay bestie, so this is the manual for std::basic_regex from the C++ standard library (3cxx section, iykyk). it's literally the class template for regular expressions and we're about to get into it π
πΈ NAME πΈ
std::basic_regex< _Ch_type, _Rx_traits > β A regular expression. that's it. that's the vibe. π
π¦ SYNOPSIS π¦
#include <regex>
π Public Types
typedef regex_constants::syntax_option_type flag_typeβ the type for all those grammar flags β¨typedef traits_type::locale_type locale_typeβ locale vibestypedef traits_type::string_type string_typeβ string vibestypedef _Rx_traits traits_typeβ traits, obvitypedef _Ch_type value_typeβ the char type, main character energy π
π Public Member Functions
basic_regex () noexceptβ default constructor, no args neededtemplate<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 inf.basic_regex (basic_regex &&__rhs) noexcept=defaultβ Move-constructs a basic regular expression. slay, efficient.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 inf.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 stringsinterpreted according to the flags inf.basic_regex (initializer_list< _Ch_type > __l, flag_type __f=ECMAScript)β Constructs a basic regular expression from an initializer list. cute and compact π~basic_regex ()β Destroys a basic regular expression. rip bestie π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 toassign().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. giving it the vibes β¨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. trading places, iconic π
π Static Public Attributes
Constants
std [28.8.1](1)
static constexpr flag_type icaseβ case-insensitive flagstatic constexpr flag_type nosubsβ no subexpressions flagstatic constexpr flag_type optimizeβ optimization flagstatic constexpr flag_type collateβ collate flagstatic constexpr flag_type ECMAScriptβ the ECMAScript grammar flag (the default, main character energy π)static constexpr flag_type basicβ basic POSIX grammar flagstatic constexpr flag_type extendedβ extended POSIX grammar flagstatic constexpr flag_type awkβ awk grammar flagstatic constexpr flag_type grepβ grep grammar flagstatic constexpr flag_type egrepβ egrep grammar flagstatic constexpr flag_type multilineβ multiline flag β¨
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)β friend function, internal regex algorithm impltemplate<typename , typename , typename , bool > class __detail::_Executorβ friend class, the executor
Related Symbols
(Note that these are not member symbols.)
template<typename _Ch_type , typename _Rx_traits > void swap (basic_regex< _Ch_type, _Rx_traits > &__lhs, basic_regex< _Ch_type, _Rx_traits > &__rhs) noexceptβ Swaps the contents of two regular expression objects. the free-function version, we love to see it π«Ά
π Detailed Description π
template<typename _Ch_type, typename _Rx_traits = regex_traits<_Ch_type>>
class std::basic_regex< _Ch_type, _Rx_traits >
"A regular expression.
okay so here's the tea bestie: 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>. iykyk β¨
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. it's giving compiler energy fr fr π
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. so many options, all iconic π
Since: C++11 π
π§ Constructor & Destructor Documentation π§
constructor: basic_regex ()
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. it's the empty regex, lowkey useless but highkey valid β¨
constructor: basic_regex (const _Ch_type *__p, flag_type __f = ECMAScript)
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_errorif__pis not a valid regular expression. so if you mess up, you'll know π
constructor: basic_regex (const _Ch_type *__p, std::size_t __len, flag_type __f = ECMAScript)
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_errorif__pis not a valid regular expression. bestie pls validate π
constructor: basic_regex (const basic_regex< _Ch_type, _Rx_traits > & __rhs)
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. twin vibes π«Ά
Parameters
__rhsβ A regex object.
constructor: basic_regex (basic_regex< _Ch_type, _Rx_traits > && __rhs)
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. moving on up, no cap π
Parameters
__rhsβ A regex object.
constructor: basic_regex (const std::basic_string< _Ch_type, _Ch_traits, _Ch_alloc > & __s, flag_type __f = ECMAScript)
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. string girlies rise π
Parameters
__sβ A string containing a regular expression.__fβ Flags indicating the syntax rules and options.
Exceptions
regex_errorif__sis not a valid regular expression.
constructor: basic_regex (_FwdIter __first, _FwdIter __last, flag_type __f = ECMAScript)
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. iterators bestie, we love a range π¦
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_errorif[__first, __last)is not a valid regular expression.
References: std::basic_regex< _Ch_type, _Rx_traits >::assign().
constructor: basic_regex (initializer_list< _Ch_type > __l, flag_type __f = ECMAScript)
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. { 'a', 'b', 'c' } type beat β¨
Parameters
__lβ The initializer list.__fβ The format flags of the regular expression.
Exceptions
regex_errorif__lis not a valid regular expression.
destructor: ~basic_regex ()
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. bye bestie, it was real ππ«Ά
π MEMBER FUNCTION DOCUMENTATION π
Okay so this is the member-function era, and it's giving regex glow-up montage. Every overload of assign(), every operator=, plus the cute little utility functions β all here, bestie. No skips, no cap. β¨
πΈ assign() overloads: set the pattern, set the vibe πΈ
π assign(_InputIterator __first, _InputIterator __last, flag_type __flags = ECMAScript) β range edition
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. It's a whole range moment, from __first to __last, and your regex object gets the assignment treatment.
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_errorifpdoes not contain a valid regular expression pattern interpreted according to__flags. Ifregex_erroris thrown, the object remains unchanged.
References: std::basic_regex< _Ch_type, _Rx_traits >::assign().
π assign(basic_regex< _Ch_type, _Rx_traits > && __rhs) β move-assign, noexcept queen
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. Very "your pattern is my pattern now" energy. π
Parameters:
__rhsβ Another regular expression object.
References: std::move().
π assign(const _Ch_type * __p, flag_type __flags = ECMAScript) β C-string energy
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_errorif__pdoes not contain a valid regular expression pattern interpreted according to__flags. Ifregex_erroris thrown,*thisremains unchanged.
π¦ assign(const _Ch_type * __p, size_t __len, flag_type __flags = ECMAScript) β pointer + length combo
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. This one lets you say exactly how long the pattern string is β very "I brought receipts" of it all. π§Ύ
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_errorifpdoes not contain a valid regular expression pattern interpreted according to__flags. Ifregex_erroris thrown,*thisremains unchanged.
π assign(const basic_regex< _Ch_type, _Rx_traits > & __rhs) β copy-assign, noexcept
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. Copy-paste but make it regex, and make it noexcept. β¨
Parameters:
__rhsβ Another regular expression object.
Referenced by std::basic_regex< _Ch_type, _Rx_traits >::basic_regex(), std::basic_regex< _Ch_type, _Rx_traits >::assign(), std::basic_regex< _Ch_type, _Rx_traits >::operator=(), std::basic_regex< _Ch_type, _Rx_traits >::operator=(), and std::basic_regex< _Ch_type, _Rx_traits >::operator=().
π assign(const basic_string< _Ch_type, _Ch_traits, _Alloc > & __s, flag_type __flags = ECMAScript) β string assign
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. String girlies, this one's for you. π
Parameters:
__sβ A string containing a regular expression pattern.__flagsβ Syntax option flags.
Exceptions:regex_errorif__sdoes not contain a valid regular expression pattern interpreted according to__flags. Ifregex_erroris thrown,*thisremains unchanged.
References: std::basic_string< _CharT, _Traits, _Alloc >::data(), and std::basic_string< _CharT, _Traits, _Alloc >::size().
π assign(initializer_list< _Ch_type > __l, flag_type __flags = ECMAScript) β init-list cuteness
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. This is the initializer_list route, so you can hand it a little pattern bundle all bracketed and cute. π
Parameters:
__lβ An initializer list representing a regular expression.__flagsβ Syntax option flags.
Exceptions:regex_errorif__ldoes not contain a valid regular expression pattern interpreted according to__flags. Ifregex_erroris thrown, the object remains unchanged.
β flags() β what flags though? β
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(). Basically: what syntax-energy was this regex built with, bestie? π
π§ getloc() β locale check π§
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. Locale tea, served fresh. π«
π imbue(locale_type __loc) β locale infusion π
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.
π mark_count() β count the marked subexpressions π
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. It's giving "how many little groups did we mark in here?" main character energy. π
π
operator= overloads: replace the pattern, keep it iconic π
π₯ operator=(basic_regex< _Ch_type, _Rx_traits > &&) β move-assign default
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. Default behavior, still slaying. π₯
π operator=(const _Ch_type * __p) β C-style string replacement
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.
References: std::basic_regex< _Ch_type, _Rx_traits >::assign().
π«Ά operator=(const basic_regex< _Ch_type, _Rx_traits > &) β copy-assign default
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. Default copy behavior, no extra drama. π«Ά
πΈ operator=(const basic_string< _Ch_type, _Ch_traits, _Alloc > & __s) β string replacement
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.
References: std::basic_regex< _Ch_type, _Rx_traits >::assign().
π operator=(initializer_list< _Ch_type > __l) β init-list replacement
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_errorif__lis not a valid regular expression.
References: std::basic_regex< _Ch_type, _Rx_traits >::assign().
π¦ swap() β trade patterns like friendship bracelets π¦
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. Mutual exchange, but make it regex. π¦
Parameters:
__rhsβ Another regular expression object.
β¨ AUTHOR β¨
Generated automatically by Doxygen for libstdc++ from the source code. So no mysterious human author credit here, bestie β it's the Doxygen machine doing its thing. π
Cute footer sign-off: the footer's source/version-and-date tea is that this page is generated automatically by Doxygen for libstdc++ from the source code, and it's the libststd::basic_rege...e, _Rx_traits >(3cxx) manual page. That's the whole auto-generated glow. π
β¨
π¦ where this page comes from
- ubuntu noble: libstdc++-14-doc 14-20240412-0ubuntu1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms