-2

I am crazy about this question. In R language regex, how to match a pattern "_a (b)"? a and b both stand for a word, there is a space in front of (.

library(stringr)
x <- c("dum_drop (words)", "apple")
# I want to match and remove the part "_drop (words)"
str_remove(x, pattern = "[_drop (words)]")
# result
# [1] "um_drop (words)" "aple" 

I think the regex expression about the pattern "_drop (words)" needs some work.

Beryl
  • 39
  • 5

1 Answers1

0

Correct match:

x <- c("dum_drop (words)", "apple")
str_remove(x, pattern = "_drop [(]words[)]")
# result
# [1] "dum"   "apple"

Beryl
  • 39
  • 5