regular expression with the character of dash

for special character, I think escaping with \\ in R will do the trick. Here is an example where \\- match -

gsub("\\-", "+", "re-entry")
#> [1] "re+entry"
gsub("[^a-zA-Z0-9&\\-]", "+", "re-entry*")
#> [1] "re-entry+"
3 Likes