X <- c("ABC(DEF)", "ABC")sub(".*(?:\\((.*)\\)).*|.*", "\\1",X)
Standard input is empty
[1] "DEF" ""
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!