FUNCTION::NGROUPS(3stap)

πŸ’– FUNCTION::NGROUPS πŸ’–

okay bestie, we're in the 3stap manual β€” the SystemTap Tapset Reference situation β€” and this little cutie is a function, so let's get into it 🫢


✨ NAME ✨

function::ngroups β€” Number of subexpressions in the last match. literally that's the whole job. she's niche but she's iconic πŸ‘‘


🌸 SYNOPSIS 🌸

ngroups:long()

πŸŽ€ ARGUMENTS πŸŽ€

None. no arguments, no notes, she takes nothing from you πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So ngroups returns the number of subexpressions from the last successful use of the =~ regex matching operator. that's it. that's the vibe check ✨

Now here's the part you gotta hear, no cap: this number includes subexpressions that are present in the regex but did not match any string. so if you're like "wait, that group didn't match anything, why is she counted" β€” because that's just how it is, bestie 😭 for example, given the regex "a|(b)", the subexpressions will count the group for (b) regardless of whether it matched a string or not. counted anyway. she said inclusivity periodt πŸ’œ

⚠️ and be careful: it throws an error if the last use of =~ was a failed match. so like... if the match flopped, don't come asking her for a number, she will simply scream at you. main character energy but make it hostile πŸ™ˆ

🌈 SEE ALSO 🌈

  • tapset::regex(3stap)

and that's the whole page, you ate it πŸ’… this was the SystemTap Tapset Reference, version note dated September 2026 β€” mwah, go slay some regexes, ily πŸ§šπŸ’–βœ¨

πŸ“¦ where this page comes from