【发布时间】:2020-10-21 17:48:42
【问题描述】:
我怎样才能在文本中得到我期望的输出,如下例所示?
x<-c("Commerce recommend erkanexample.com.tr. This site erkanexample.com. erkandeneme.com is widely. The company name is apple.commerce is coma. spread")
x<-gsub("(.com)\\S+", "",x)
x
[1] "Commerce r erkanexample This site erkanexample erkandeneme.com is widely. The name is apple is"
expected
[1] "Commerce recommend This site. is widely. The company name is apple.commerce is coma. spread"
>
【问题讨论】:
-
试试
x<-gsub("\\s*\\S+\\.com\\b(?:\\.\\S+)?", "", x) -
如果上述方法不起作用,请尝试
gsub("\\s*\\S+\\.com(?:\\.\\w+)*\\b", "", x)。 -
任何解决方案都有效吗?
-
非常感谢@Wiktor Stribiżew 和大家。两者似乎都有效。我希望您给我一些时间来全面检查我拥有的数据库。
-
代码是有效的。谢谢。