get_number_of_groups(pattern, ...)
re2
Return the number of capturing subpatterns, or -1 if the regexp wasn't valid on construction. The overall match ($0) does not count: if the regexp is "(a)(b)", returns 2.
regexp = re2("1") get_number_of_groups(regexp)[1] 0get_number_of_groups(re2("((?P<a>123)(12))"))[1] 3# uncaptured groups get_number_of_groups(re2("(?:(?:(?:(?:(?:.)?){100})*)+)"))[1] 0