:space: portion of the regex makes no sense, and probably does not do what you intend.
> x <- "abc:def."
> gsub("[^a-zA-Z0-9,-:space:]", " ", x, perl = TRUE)
Notice that the colon and period are still present after the substitution.
In fact, inside the character class,
,-: means "all characters with ASCII codes from 44 (the comma) up to 58 (the colon)".
A literal hyphen must be the first or the last character in a character class; otherwise, it is treated as a range (like
If you want a character class for whitespace, use
So, if you wanted to convert all consecutive strings of junk to a single space, preserving only letters, digits, commas, slashes, hyphens, and whitespace, you could write:
gsub("[^-,/a-zA-Z0-9[:space:]]+", " ", x, perl = TRUE)
gsub("[^-,/a-zA-Z0-9\\s]+", " ", x, perl = TRUE)