tags:

views:

50

answers:

1

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#

+3  A: 

This is one way:

Console.WriteLine(Regex.Replace("Oh Boy!!#$", @"[^\w ]", ""));
steinar
Good. Simple. Like it.
spender
Works like a charm!! Which is a good site to learn regex?
Prog
NETQuestion
This one is at least a good reference: http://www.regular-expressions.info/, also the MSDN article is a must read (http://msdn.microsoft.com/en-us/library/az24scfc.aspx). (If you're serious about it, you might also want to check out the book Mastering regular expressions from O'Reilly.)
steinar
Rad Software Regular Expression Designer really helped me sussing out Regex. http://www.radsoftware.com.au/regexdesigner/ It's free.
spender