在R中替换文本AFTER模式

时间:2018-10-16 10:52:30

标签: r regex grep gsub

我在这里尝试删除遵循文本行中某个模式的文本时有点不知所措。我想删除"Typ 142"之后的所有内容。这是我得到的:

b <- "Do you have any comments or requests regarding this survey, data management, or data publishing in general? These comments are for internal use only and will not be made public. (q_753959 - Typ 142)dojo.require('dijit.Tooltip');Bitte beachten Sie dass obwohl der Fragename die Question-ID enthält es ein eigenständiger Bezeichner ist. In kopierten Umfragen b etc."

但是,包括模式在内的所有内容均被删除。我已经尝试了很多事情,但到目前为止没有任何效果。

a <- sub('(Typ [0-9]{3}\\)).*', '', b)

 "Do you have any comments or requests regarding this survey, data management, or data publishing in general? These comments are for internal use only and will not be made public. (q_753959 - "

非常感谢!

1 个答案:

答案 0 :(得分:0)

sub("(?<=Typ \\d{3}\\)).*","",b,perl=TRUE)
相关问题