Remove text inside brackets, parens, and/or braces

前端 未结 4 544
情话喂你
情话喂你 2020-12-16 22:22

I am in need of a function that extracts any type of bracket ie (), [], {} and the information in between. I created it and get it to do what I want but I get an annoying w

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-16 23:25

    My thought had been to make 6 (implicitly vectorized) helper functions, but I will be studying Martin's code instead, since he is much better at this than I:

    rm.curlybkt.no <-function(x) gsub("(\\{).*(\\})", "\\1\\2", x, perl=TRUE)
    rm.rndbkt.no <-  function(x) gsub("(\\().*(\\))", "\\1\\2", x, perl=TRUE)
    rm.sqrbkt.no <-  function(x) gsub("(\\[).*(\\])", "\\1\\2", x, perl=TRUE)
    
    rm.rndbkt.in <- function(x) gsub("\\(.*\\)", "", x)
    rm.curlybkt.in <- function(x) gsub("\\{.*\\}", "", x)
    rm.sqrbkt.in   <- function(x) gsub("\\[.*\\]", "", x)
    

提交回复
热议问题