Specifies how many times a pattern should occur. This function acts as a quantifier, allowing for exact counts, ranges, or unbounded "many" matches.
xp_op_repeat(pattern, n, max = NULL)A regexpert object.
The function automatically optimizes common regex quantifiers:
0 to Inf becomes *
1 to Inf becomes +
Exact counts use {n}
It also wraps the incoming pattern in a non-capturing group (?:)
to ensure the quantifier applies to the entire preceding logic rather than
just the last character.
# Match exactly 3 digits
xp_build_digits() %>% xp_op_repeat(3)
#> <regexpert pattern>
#> (?:\d){3}
# Match between 2 and 5 lowercase letters
xp_build_letters(case = "lower") %>% xp_op_repeat(2, 5)
#> <regexpert pattern>
#> (?:[a-z]){2,5}
# Match 1 or more alphanumeric characters
xp_build_alnum() %>% xp_op_repeat(1, Inf)
#> <regexpert pattern>
#> (?:[A-Za-z0-9])+