How to escape closed bracket "]" in regex in R -
i'm trying use gsub
in r replace bunch of weird characters in strings i'm processing. works, except whenever throw in "]" makes whole thing nothing. i'm using \\
gsub("[\\?\\*\\]]", "", name)
it's still not working. here's actual example:
name <- "r u still down? [remember me]"
what want is: names
"r u still down remember me"
when do: names <- gsub("[\\(\\)\\*\\$\\+\\?'\\[]", "", name)
semi-works , "r u still down remember me]"
but when do: names <- gsub("[\\(\\)\\*\\$\\+\\?'\\[\\]]", "", name)
nothing happens. (i.e. "r u still down? [remember me]"
)
any ideas? i've tried switching around order of things, etc. can't seem figure out.
just enable perl=true
parameter.
> gsub("[?\\]\\[*]", "", name, perl=t) [1] "r u still down remember me"
and escape needed characters.
> gsub("[()*$+?'\\[\\]]", "", name, perl=t) [1] "r u still down remember me"
Comments
Post a Comment