std::match_...s::position(3)

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

bestie, you found the std::match_...s::position(3) page from the C++ Standard Libary, and honestly it's giving β€œtiny but important regex detail” energy πŸ’…. The manual name is folded in right here so the header line doesn't have to be copy-pasted β€” we're doing cute formatting, not boring formatting.

✨ NAME ✨

std::match_results::position - std::match_results::position

Yes, the NAME section is literally the function naming itself. Iconic, lowkey self-obsessed, but valid πŸŽ€.

πŸ¦‹ Synopsis πŸ¦‹

difference_type position( size_type n = 0 ) const;  (since C++11)

It returns the position of the first character of the specified sub-match. Here's the breakdown, bestie:

  • If n == 0, the position of the first character of the entire matched expression is returned.
  • If n > 0 && n < size(), the position of the first character of the nth sub-match is returned.
  • If n >= size(), a position of the first character of the unmatched match is returned.

πŸŽ€ Parameters πŸŽ€

  • n β€” integral number specifying which match to examine.

πŸ’– Return value πŸ’–

The position of the first character of the specified match or sub-match. That's it. That's the tea β˜•βœ¨.

🌈 Example 🌈

// Run this code

#include <iostream>
#include <regex>
#include <string>

int main()
{
    std::regex re("a(a)*b");
    std::string target("aaab");
    std::smatch sm;

    std::regex_match(target, sm, re);
    std::cout << sm.position(1) << '\n';
}

⭐ Output: ⭐

2

πŸ‘‘ See also πŸ‘‘

  • operator[] β€” returns specified sub-match (public member function).

okay so the cute sign-off: source http://cppreference.com, version/date stamp 2024.06.10, footer title std::match_...s::position(3) β€” signed off with sparkles and zero boring manpage energy πŸ§šπŸ’œ

πŸ“¦ where this page comes from