Replace/Remove characters that do not match the Regular Expression (.NET)

I have a regular expression to validate a string. But now I want to remove all the characters that do not match my regular expression.

E.g.

regExpression = @"^([\w\'\-\+])"

text = "This is a sample text with some invalid characters -+%&()=?";

//Remove characters that do not match regExp.

result = "This is a sample text with some invalid characters -+";

Any ideas of how I can use the RegExpression to determine the valid characters and remove all the other ones.

Many thanks

13
задан tif 27 May 2011 в 15:49
поделиться