Consider the following example:
x <- "something('pineapple', 'orange', y = c('peach', 'banana'), z = 'lemon'), something(v = c('apple', 'pear'), z = c('cherry', 'strawberry', 'grape'))"
I want to extract the segments encapsulated by something(
and its matching )
. Thus, the respective function should extract "something('pineapple', 'orange', y = c('peach', 'banana'), z = 'lemon')"
and "something(v = c('apple', 'pear'), z = c('cherry', 'strawberry', 'grape'))"
in this example. There can be any number of parentheses within something()
. Thus, I cannot simply extract everything from something(
to the next )
. That would e.g. return the first segment as "something('pineapple', 'orange', y = c('peach', 'banana')"
.
I am essentially looking to fill in the regex placeholder in
stringr::str_extract_all(x, "something\\(<text until matching parenthesis>")