We help IT Professionals succeed at work.

regex not stripping special chars

Focker513
Focker513 asked
on
string temp = Regex.Replace(txt.Text, "[^a-zA-Z0-9 .]+",String.Empty,RegexOptions.Compiled);

This still allows Test! Test# ...

I must be missing the point here.
Comment
Watch Question

Project Lead
Top Expert 2011
Commented:
Try with this


Regex r = new Regex("(?:[^a-z0-9 ]|(?<=['\"])s)", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.Compiled);
    string temp = r.Replace(txt.Text, String.Empty);

Author

Commented:
Thanks