name<-c("Dr. T. (Tom) Bailey (m), UCL- Physics" , "Dr. B.K. (Barbara) Blue (f), Oxford - Political Science", "Dr. T. (Tim) Ford, UCL- Physics", "Dr. T. (Tom) Bailey (m ) some text")res <- sub(".*?\\)\\s*(.*?)\\s*(?:\\(\\s*[mf]\\s*\\)|,).*", "\\1", name)res
Standard input is empty
[1] "Bailey" "Blue" "Ford" "Bailey"
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!