假设我有一些这样的文字,
text<-c("[McCain]: We need tax policies that respect the wage earners and job creators. [Obama]: It's harder to save. It's harder to retire. [McCain]: The biggest problem with American healthcare system is that it costs too much. [Obama]: We will have a healthcare system, not a disease-care system. We have the chance to solve problems that we've been talking about... [Text on screen]: Senators McCain and Obama are talking about your healthcare and financial security. We need more than talk. [Obama]: ...year after year after year after year. [Announcer]: Call and make sure their talk turns into real solutions. AARP is responsible for the content of this advertising.")
我想删除(编辑:摆脱) [ 和 ] (以及括号本身)之间的所有文本。最好的方法是什么?这是我使用正则表达式和 stingr 包的无力尝试:
str_extract(text, "\\[[a-z]*\\]")
谢谢你的帮助!
有了这个:
gsub("\\[[^\\]]*\\]", "", subject, perl=TRUE);
正则表达式的含义:
\[ # '['
[^\]]* # any character except: '\]' (0 or more
# times (matching the most amount possible))
\] # ']'
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)