Reputation: 9939
I have a small Regex here where I am removing all the white spaces from within a file and replacing them with '-'.
I want to also replace other characters with '-' such as ',' and '_'.
How can I list these characters in my regex?
Regex r = new Regex(@"\s+");
string fileName = r.Replace(Files.Name, @"-");
Upvotes: 1
Views: 1698
Reputation: 111820
Regex r = new Regex(@"[\s,_-]+");
string fileName = r.Replace(Files.Name, @"-");
Be aware that the -
must be the first, the last or you'll need escaping.
Upvotes: 4