fork download
  1. library(stringr)
  2. test <- "asdf asiodjfojewl kjwnkjwnefkjnkf [asdf] fasdfads fewrw [keyword<1] keyword [keyword>1]"
  3. ## If the word is right after "[":
  4. str_extract_all(test, "(?<=\\[)keyword[^\\]\\[]*(?=])")
  5. ## If the word is anywhere betwee "[" and "]":
  6. str_extract_all(test, "(?<=\\[)[^\\]\\[]*?keyword[^\\]\\[]*(?=])")
Success #stdin #stdout 0.28s 43816KB
stdin
Standard input is empty
stdout
[[1]]
[1] "keyword<1" "keyword>1"

[[1]]
[1] "keyword<1" "keyword>1"