std::basic_...:mark_count(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– 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