Prog
Prog

Reputation: 23

Regular expression to check for special characters except space

I want to check for special characters in a string EXCEPT spaces and delete them.

Ex: input = "Oh Boy!!#$" output = "Oh Boy"

Can someone help me with the regular expression to implement this in C#

Upvotes: 2

Views: 4206

Answers (1)

steinar
steinar

Reputation: 9663

This is one way:

Console.WriteLine(Regex.Replace("Oh Boy!!#$", @"[^\w ]", ""));

Upvotes: 5

Related Questions