get_number_of_groups: Return the number of capturing subpatterns

Description Usage Arguments Value Examples

Description

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.

Usage

1

Arguments

pattern

a pre-compiled regular expression or a string

...

further arguments passed to re2

Value

a integer

Examples

1
2
3
4
5
6
7
regexp = re2("1")
get_number_of_groups(regexp)

get_number_of_groups(re2("((?P<a>123)(12))"))

# uncaptured groups
get_number_of_groups(re2("(?:(?:(?:(?:(?:.)?){100})*)+)"))

Example output

[1] 0
[1] 3
[1] 0

re2r documentation built on May 2, 2019, 12:35 p.m.