How does one use regex expressions in R to replace the nested parenthesis in this example:
chf <- "(Mn,Ca,Zn)5(AsO4)2((AsO3)OH)24(H2O)(OH(AsO3))(OH(AsO3)OH)"
The desired output is
"(Mn,Ca,Zn)5(AsO4)2(AsO3OH)24(H2O)(OHAsO3)(OHAsO3OH)"
I'm trying this but I'm not able to exclude what's inside the nested brackets.
> str_replace_all(chf,"\\((\\w+)\\)","(gone)")
[1] "(Mn,Ca,Zn)5(gone)2((gone)OH)24(gone)(OH(gone))(OH(gone)OH)"