I am trying to remove everything in a string except spaces dashes(-) and letters.
For example
string1 <- "test-%432string *#$ one!~+"
how do I return “test-string one”
I tried :
gsub("[^a-zA-Z-\s]", "", string1)
to no avail — it removes the space, which should be left.
Thanks for any help.
Try this
That worked for me. You can try it out on rubular.com.
Enjoy.
Or in R form: