Reputation: 73978
I need help in writing a RegEx able to detect 1 or more instance of a defined characters in a string (in my example an empty space) and replace with a single DASH.
I'm using at the moment this RegEx, it replace one ore more instances of an Empty Space in a string.
Regex.Replace(inputString, @"\s+", "-");
I would like have a similar approach but for another character example:
;
or &
.
Any idea how to solve it? Thansk for your time on this.
Upvotes: 0
Views: 104
Reputation: 93026
Regex.Replace(inputString, @"[;&]+", "-");
[;&]
is a character class containing the characters inside the square brackets. You can add there all characters you want to have replaced.
If you want to combine with your working solution, just add \s
to the class
Regex.Replace(inputString, @"[\s;&]+", "-");
Upvotes: 1