0

I have some data that looks like this:

n <- ("String [a]", "String2 [b]")

I'd like to remove the brackets and everything within them so I get this:

n <- ("String", "String2")

The code I have is:

gsub("\\[*]", "", n)

Which doesn't work because the \ mean R interprets the wildcard * literally. How do I fix this? Thanks!

filler
  • 1
  • 4
    `gsub("\\[.*\\]", "", n)` the "wildcard" is `.` (the asterisk `*` is a metacharacter for zero or more instances of the preceding character). Also you need to escape both brackets. – dario Nov 03 '21 at 23:25

0 Answers0