string <- "text1 text2(stuff)(blahh) text3"sub(".*text2\\([^()]*\\)(?:\\(([^()]*)\\))?.*", "\\1", string, perl=TRUE)
Standard input is empty
[1] "blahh"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!