STD::BASIC_REGEX(3)
β¨ std::basic_regex< _Ch_type, _Rx_traits > β¨
Library Functions Manual Β· manual page std::basic_regex< _Ch_type, _Rx_traits >(3)
πΈ NAME πΈ
std::basic_regex< _Ch_type, _Rx_traits > β A regular expression.
β¨ SYNOPSIS β¨
#include <regex>
π¦ Public Types π¦
typedef regex_constants::syntax_option_type flag_typetypedef traits_type::locale_type locale_typetypedef traits_type::string_type string_typetypedef _Rx_traits traits_typetypedef _Ch_type value_type
π Public Member Functions π
basic_regex () noexceptβ Constructs a basic regular expression that does not match any character sequence. It's giving "matches nothing, knows exactly what it is" energy.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 inf.basic_regex (basic_regex &&__rhs) noexcept=defaultβ Move-constructs a basic regular expression. Slay, no copy needed.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.~basic_regex ()β Destroys a basic regular expression. Gone, but never forgotten.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.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 icasestatic constexpr flag_type nosubsstatic constexpr flag_type optimizestatic constexpr flag_type collatestatic constexpr flag_type ECMAScriptstatic constexpr flag_type basicstatic constexpr flag_type extendedstatic constexpr flag_type awkstatic constexpr flag_type grepstatic constexpr flag_type egrepstatic 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> class __detail::_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.
π 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
π₯ Constructor & Destructor Documentation π₯
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.
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.
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.
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.
Parameters:
__rhsβ A regex object.
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.
Parameters:
__rhsβ A regex object.
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.
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.
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.
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.
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.
Parameters:
__lβ The initializer list.__fβ The format flags of the regular expression.
Exceptions:
regex_errorif__lis not a valid regular expression.
~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.
π Member Function Documentation π
Okay bestie, this is the member-function roll call. Every overload, every parameter, every exception, every noexcept β we are not missing a single crumb. Let's go. π
β¨ assign β iterator 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]
Bestie, this one takes a range from __first to __last and assigns a brand-new regular expression to your regex object. It's giving "new pattern, who dis?" energy. β¨
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.
Not me side-eyeing the fact that the original saysphere even though the params are__firstand__last. We keep it exactly as written, bestie. No editing the source. π
β¨ assign β move edition β¨
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. It's noexcept, so it's basically the chill, drama-free overload. π«Ά
Parameters
__rhsβ another regular expression object.
β¨ assign β C-style null-terminated string edition β¨
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. Classic C-string behavior, but make it regex. πΈ
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 β C-style string with length edition β¨
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. Now with __len, because sometimes you don't trust null terminators. Periodt. π
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 β copy another regex edition β¨
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 yes, it's noexcept. Iconic. π
Parameters
__rhsβ another regular expression object.
Referenced by std::basic_regex< char >::basic_regex(), std::basic_regex< char >::assign(), std::basic_regex< char >::operator=(), std::basic_regex< char >::operator=(), and std::basic_regex< char >::operator=().
β¨ assign β basic_string edition β¨
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. Yes, a whole basic_string, with _Ch_traits and _Alloc and everything. So fancy. π
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.
β¨ assign β initializer_list edition β¨
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 one takes an initializer list, so you can flex your regex pattern in curly braces. Slay. β¨
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 β¨
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(). It's the receipts for your syntax options. π§Ύπ
β¨ getloc β¨
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 check, bestie. π
β¨ imbue β¨
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. It's giving "I'm changing the vibe of this regex." π«
Parameters
__locβ a locale.
β¨ mark_count β¨
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. Count your capture groups, bestie. It's math but make it regex. π’
β¨ operator= β move edition β¨
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. Defaulted, so the compiler said "I got this." π«Ά
β¨ operator= β C-style null-terminated string edition β¨
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. New pattern, new me. π
Parameters
__pβ a pointer to the start of a null-terminated C-style string containing a regular expression.
β¨ operator= β copy another regex edition β¨
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. Defaulted, clean, no notes. β¨
β¨ operator= β basic_string edition β¨
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. String girlies, this one's for you. π
Parameters
__sβ a pointer to a string containing a regular expression.
β¨ operator= β initializer_list edition β¨
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. Curly braces, but make it regex. π
Parameters
__lβ the initializer list.
Exceptions
regex_errorif__lis not a valid regular expression.
β¨ swap β¨
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. It's a trade, a barter, a little regex swap meet. And it's noexcept, so no drama. π
Parameters
__rhsβ another regular expression object.
π Author π
Generated automatically by Doxygen for libstdc++ from the source code.
And that's the whole page, bestie. The footer's got the libstdc++ source/version tag and the date baked in, plus the page name std::basic...x_traits >(3). Doxygen really said "I'll generate it, you go off." Mwah. πβ¨
π¦ where this page comes from
- arch rolling: gcc 16.2.1+r23+gd564253eb6c8-1 Β· GPL-3.0-or-later WITH GCC-exception-3.1 AND GFDL-1.3-or-later
- fedora 44: libstdc++-docs 16.0.1-0.10.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- fedora 44: libstdc++-docs 16.2.1-2.fc44
- fedora 44: libstdc++-docs 16.2.1-3.fc44 Β· GPL-3.0-or-later AND LGPL-3.0-or-later AND (GPL-3.0-or-later WITH GCC-exception-3.1) AND (GPL-3.0-or-later WITH Texinfo-exception) AND (LGPL-2.1-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GCC-exception-2.0) AND (GPL-2.0-or-later WITH GNU-compiler-exception) AND BSL-1.0 AND GFDL-1.3-or-later AND Linux-man-pages-copyleft-2-para AND SunPro AND BSD-1-Clause AND BSD-2-Clause AND BSD-2-Clause-Views AND BSD-3-Clause AND BSD-4-Clause AND BSD-Source-Code AND Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 WITH LLVM-Exception) AND ZPL-2.1 AND ISC AND LicenseRef-Fedora-Public-Domain AND HP-1986 AND curl AND Martin-Birgmeier AND HPND-Markus-Kuhn AND dtoa AND SMLNJ AND AMD-newlib AND OAR AND HPND-merchantability-variant AND HPND-Intel
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms