x <- c("[ghjg6] [fdg5] [113gi4lki] great work", "[xzswedc: acf] [xzt8] [111eerrh5]", "[asd2] [1] [113vu17hg 115er5lgr 112cgnmbh ] get out", "Some text with no brackets")df <- data.frame(x)df$x = sub(".*\\[([^][]+)].*|.*", "\\1", df$x)df
Standard input is empty
x 1 113gi4lki 2 111eerrh5 3 113vu17hg 115er5lgr 112cgnmbh 4
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!