std::basic_regex(3)
π std::basic_regex
okay so bestie, buckle up β this one's from the C++ Standard Library manual (section 3, yes it's literally a "Libary" in the original header and we respect the typo π«Ά). It's giving regex but make it a class template, and honestly? Iconic.
β¨ NAME β¨
std::basic_regex β which is, and I cannot stress this enough, std::basic_regex π
πΈ SYNOPSIS πΈ
Defined in header <regex>:
template<
class CharT, (since C++11)
class Traits = std::regex_traits<CharT>
> class basic_regex;
So like β the class template basic_regex provides a general framework for holding regular expressions. That's it, that's the whole job, and it does it slayfully.
There are also several typedefs for the common character types, pre-baked for your convenience π β defined in header <regex>:
std::regexβ defined asstd::basic_regex<char>std::wregexβ defined asstd::basic_regex<wchar_t>
π¦ Member types π¦
the little type-alias family photo:
value_typeβ defined asCharTtraits_typeβ defined asTraitsstring_typeβ defined asTraits::string_typelocale_typeβ defined asTraits::locale_typeflag_typeβ defined asstd::regex_constants::syntax_option_type
π Member functions π
- constructor β constructs the regex object (public member function)
- destructor β destructs the regex object (public member function)
operator=β assigns the contents (public member function)assignβ assigns the contents (public member function)
β Observers β
mark_countβ returns the number of marked sub-expressions within the regular expression (public member function)flagsβ returns the syntax flags (public member function)
π Locale π
getlocβ get locale information (public member function)imbueβ set locale information (public member function)
π§ Modifiers π§
swapβ swaps the contents (public member function)
π CONSTANTS π
okay this is the part where you actually pay attention, bestie, this is the main character section π₯
Grammer options (grammar options, but make it cute)
ECMAScriptβ Use the Modified ECMAScript regular expression grammar.basicβ Use the basic POSIX regular expression grammar (grammar documentation).extendedβ Use the extended POSIX regular expression grammar (grammar documentation).awkβ Use the regular expression grammar used by theawkutility in POSIX (grammar documentation).grepβ Use the regular expression grammar used by thegreputility in POSIX. This is effectively the same as thebasicoption with the addition of newline'\n'as an alternation separator.egrepβ Use the regular expression grammar used by thegreputility, with the-Eoption, in POSIX. This is effectively the same as theextendedoption with the addition of newline'\n'as an alternation separator in addition to'|'.
Grammar variations
icaseβ Character matching should be performed without regard to case.nosubsβ When performing matches, all marked sub-expressions(expr)are treated as non-marking sub-expressions(?:expr). No matches are stored in the suppliedstd::regex_matchstructure andmark_count()is zero.optimizeβ Instructs the regular expression engine to make matching faster, with the potential cost of making construction slower. For example, this might mean converting a non-deterministic FSA to a deterministic FSA.collateβ Character ranges of the form"[a-b]"will be locale sensitive.multiline(C++17) β Specifies that^shall match the beginning of a line and$shall match the end of a line, if the ECMAScript engine is selected.
β οΈ rule check, no cap: at most one grammar option can be chosen out ofECMAScript,basic,extended,awk,grep,egrep. If no grammar is chosen,ECMAScriptis assumed to be selected. The other options serve as variations, such thatstd::regex("meow", std::regex::icase)is equivalent tostd::regex("meow", std::regex::ECMAScript|std::regex::icase). (yes the manpage really said meow. we love them for that π±)
And a lil detail that matters: the member constants in basic_regex are duplicates of the syntax_option_type constants defined in the namespace std::regex_constants. fyi π
π«Ά NON-MEMBER FUNCTIONS π«Ά
std::swap(std::basic_regex)(C++11) β specializes thestd::swapalgorithm (function template)
π Deduction guides (since C++17) π
yup, they exist, go look at 'em π
β¨ and that's the whole page β¨ β brought to you by http://cppreference.com, dated 2024.06.10, and this absolutely iconic std::basic_regex(3) documentation. mwah π
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms