我想删除“not”之前的单词。当我尝试下面的代码片段时,我没有得到预期的结果。
感谢您!
test <- c("this will not work.", "'' is not one of ['A', 'B', 'C'].", "This one does not use period ending!")
gsub(".*(not .*)\\.", "\\1", test)
但是如果我将\\.
替换为[[:punct:]]
,它就能正常工作。有人能告诉我为什么第一个不起作用吗?除了句号以外,我可能需要保留其他标点符号。
> not work
> not one of ['A', 'B', 'C']
> not use period ending!
感谢您!