Extract Substring Between Parentheses
extract_between_paren.Rd
Note that unless you specify an appropriate contents_pattern
extract_between_paren
will not work as you probably expect
if there are multiple sets of parentheses. You can use exclusion patterns
to make this work better (e.g. content_pattern = '[^)]*'
).
Usage
extract_between_paren(
x,
left = "\\(",
right = "\\)",
contents_pattern = ".*"
)
extract_all_between_paren(
x,
left = "\\(",
right = "\\)",
contents_pattern = ".*",
max_iters = 100
)
Value
Character vector with NA's for elements in x
that
do not have parentheses and the substring between the first matching
parentheses.
Examples
x = c("-", "", NA, "1", "3", "1 (Alta.)", "(Sask) 20")
extract_between_paren(x)
#> [1] NA NA NA NA NA "Alta." "Sask"