Remove all text between two brackets

后端 未结 5 1397
礼貌的吻别
礼貌的吻别 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:44

    With this:

    gsub("\\[[^\\]]*\\]", "", subject, perl=TRUE);
    

    What the regex means:

      \[                       # '['
      [^\]]*                   # any character except: '\]' (0 or more
                               # times (matching the most amount possible))
      \]                       # ']'
    

提交回复
热议问题