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_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 β€” 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 in f.
  • 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 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. 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 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> class __detail::_Executor

(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_error if __p is 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_error if __p is 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_error if __s is 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_error if [__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_error if __l is 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_error if p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, the object remains unchanged.
Not me side-eyeing the fact that the original says p here even though the params are __first and __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_error if __p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains 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_error if p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains 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_error if __s does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains 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_error if __l does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is 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_error if __l is 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