# your code goes here gsub("(?:^.*?keyword\\b|\\G(?!^))[^\\[\\]]*\\K[\\[\\]]", "", "ab[ cd] ef keyword [ gh ]keyword ij ", perl=T)
Standard input is empty
[1] "ab[ cd] ef keyword gh keyword ij "
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!