I need a string with non alpha-numeric characters etc stripped out of it; I used the following:
wordsstr = Regex.Replace(wordsstr, "[^A-Za-z0-9,-_]", "");
The problem being dots (.)s are left in the string yet they are not specified to be kept. How could I make sure dots are gotten rid of too?
Many thanks.
You are specifying that they need to be kept – you’re using
,-_which is everything from U+002C to U+005F, including U+002E (period).If you meant the
,-_to just mean comma, dash and underscore you’ll need to escape the dash, such as:Alternatively, (as in Oded’s comment) put the dash as the first or last character in the set, to prevent it being interpreted as a range specifier:
If that’s not the aim, please be more specific: “non alpha-numeric characters etc” isn’t really enough information to go on.