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 vibes
  • typedef traits_type::string_type string_type β€” string vibes
  • typedef _Rx_traits traits_type β€” traits, obvi
  • typedef _Ch_type value_type β€” the char type, main character energy πŸ‘‘

πŸŽ€ Public Member Functions

  • basic_regex () noexcept β€” default constructor, no args needed
  • 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, 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 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. 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 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. 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 flag
  • static constexpr flag_type nosubs β€” no subexpressions flag
  • static constexpr flag_type optimize β€” optimization flag
  • static constexpr flag_type collate β€” collate flag
  • static constexpr flag_type ECMAScript β€” the ECMAScript grammar flag (the default, main character energy πŸ‘‘)
  • static constexpr flag_type basic β€” basic POSIX grammar flag
  • static constexpr flag_type extended β€” extended POSIX grammar flag
  • static constexpr flag_type awk β€” awk grammar flag
  • static constexpr flag_type grep β€” grep grammar flag
  • static constexpr flag_type egrep β€” egrep grammar flag
  • static 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 impl
  • template<typename , typename , typename , bool > class __detail::_Executor β€” friend class, the 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. 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_error if __p is 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_error if __p is 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_error if __s is 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_error if [__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_error if __l is 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_error if p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is 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_error if __p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains 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_error if p does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains 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_error if __s does not contain a valid regular expression pattern interpreted according to __flags. If regex_error is thrown, *this remains 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_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() β€” 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_error if __l is 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