I am trying to replace all punctuation and "not words" except for "." and "-" in a string, but am struggling to find the right combination to set up the regex expression.
I've been using the following str_replace_all() code in R, but now I want to specify to ignore "." and "-". I've tried setting it up to include things like [^.-] and ([.-]), but I'm not getting the desired output.
str_replace_all("[APPLE/O.ORANGE*PLUM-11]", regex("[\\W+,[:punct:]]", perl=T)," ")
" APPLE O ORANGE PLUM 11 " #current output
" APPLE O.ORANGE PLUM-11 " #desired output
Any suggestions would be greatly appreciated. Thanks!