std::basic_...:mark_count(3)
π NAME π
okay so bestie, this is the std::basic_regex::mark_count page from the C++ Standard Libary manual β section 3, header title std::basic_...:mark_count(3) (yes, the manual name is spelled exactly C++ Standard Libary on this page, don't come for me π
). The NAME is std::basic_regex::mark_count β literally std::basic_regex::mark_count again, because that's what the page says, periodt.
β¨ Synopsis β¨
Here's the signature, fresh out of the synopsis:
unsigned mark_count() const;
since C++11 β that's when this icon joined the chat. It returns the number of marked sub-expressions (also known as capture groups) within the regular expression. Count those cuties, bestie. β¨
π Parameters π
(none)β literally no parameters. Zero. Empty. The parameter list is not giving anything, and that's the point. π
π Return value π
The return value is the number of marked sub-expressions within the regular expression. That's the whole vibe: you call it, it counts the marked sub-expressions. Slay. π
π Exceptions π
May throw implementation-defined exceptions. So like, it may throw β and those exceptions are implementation-defined. No extra promises, no cap. Keep that in mind, bestie. π
π Example π
Run this code, it's a whole demo:
// Run this code
#include <iostream>
#include <regex>
int main()
{
std::regex r1{"abcde"};
std::cout << "r1 has " << r1.mark_count() << " subexpressions" <<
'\n';
// Expected: 0
std::regex r2{"ab(c)de"};
std::cout << "r2 has " << r2.mark_count() << " subexpressions" <<
'\n';
// Expected: 1
std::regex r3{"a(bc)d(e)"};
std::cout << "r3 has " << r3.mark_count() << " subexpressions" <<
'\n';
// Expected: 2
// Nested sub-expressions
std::regex r4{"abc(de(fg))"};
std::cout << "r4 has " << r4.mark_count() << " subexpressions" <<
'\n';
// Expected: 2
// Escaped parentheses
std::regex r5{"a(bc\\(\\)de)"};
std::cout << "r5 has " << r5.mark_count() << " subexpressions" <<
'\n';
// Expected: 1
// Using nosubs flag
std::regex r6{"ab(c)de", std::regex_constants::nosubs};
std::cout << "r6 has " << r6.mark_count() << " subexpressions" <<
'\n';
// Expected: 0
}
π Output: π
r1 has 0 subexpressions
r2 has 1 subexpressions
r3 has 2 subexpressions
r4 has 2 subexpressions
r5 has 1 subexpressions
r6 has 0 subexpressions
mwah π β source: http://cppreference.com, date/version: 2024.06.10, page: std::basic_...:mark_count(3). Go off, bestie, and remember: count your sub-expressions, not your problems. π
β¨
π¦ 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