-1

Hello I have a string such as

string="some containt[OKUUUDN?DD];some other contaian[HDJD.HHD]"

how can I remove part between [ and ]?

I tried :

gsub("[&]", "", string)

I should get :

"some containt;some other contaian"
chippycentra
  • 3,396
  • 1
  • 6
  • 24

1 Answers1

2

You can use \\[.*?] to remove everything between [ and ]. [ needs to be escaped \\[, . means everything, * means repeated 0 to n, ? means non greedy to remove not everything from the first to the last match.

gsub("\\[.*?]", "", string)
#[1] "some containt;some other contaian"
GKi
  • 37,245
  • 2
  • 26
  • 48