Hello.
I need to remove the occurrences of "!!sym(....)" from a string, keeping everything else.
But I need to keep what's inside the parentheses !!sym(....), which in turn can contain more parentheses, and the regex gets confusing.
For example, for this two strings:
"mutate(!!sym(myvars):= as.factor(!!sym(paste0(myvars,"_num", collapse=','))))"
"!!sym(paste0(x, '.Length')) / !!sym(paste0(x, '.Width'))"
I cannot just use:
"!!sym\((.+)\)"
nor
"!!sym\((.+?)\)"
lazy
and keep the captured group \1
because it matches the wrong closing parentheses.
If inside the sym() there are three opening parenthesis I need to preserve also three closing parenthesis.
I've thought of something such as
((.*\(.*){m}(.*\).*){n})
but I don't know how to force m and n to be the same numbers of repetitions.
I think there is also a "recursive pattern" way, I don't know how it's done nor if there is something simpler.