I need to clean up filenames. So I have this code:
//\W_ is any non-word character (not [^a-zA-Z0-9_]).
Regex regex = new Regex(@"[\W_]+");
return regex.Replace(source, replacement);
This works fine, but now I don't want to remove the minus (-), so I changed the regex to this:
[\W_^-]+
But that does not work. What did I miss?
Try using this regular expression :
[^\w-]+
Edit :
Seems that the right regular expression is :
[^a-zA-Z0-9-]+
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With