Remove all text between two brackets

后端 未结 5 1402
礼貌的吻别
礼貌的吻别 2020-11-27 21:23

Suppose I have some text like this,

text<-c(\"[McCain]: We need tax policies that respect the wage earners and job creators. [Obama]: It\'s harder to save         


        
5条回答
  •  被撕碎了的回忆
    2020-11-27 21:53

    The following should do the trick. The ? forces a lazy match, which matches as few . as possible before the subsequent ].

    gsub('\\[.*?\\]', '', text)
    

提交回复
热议问题