允许特定的标点符号并删除aphostrophe

时间:2016-12-09 04:03:02

标签: c# regex string apostrophe punctuation

我试图从字符串

中删除特定的标点符号

我只需保留字符串" ."," ,"," !&#34 ;," +"," *"," -"但删除所有内容,包括撇号和#34;"""例如

what's up!

必须是:

whats up!

所以这样,它会删除所有内容

string res = Regex.Replace(filtr2, @"[^\w\s]", "");  

1 个答案:

答案 0 :(得分:1)

希望您正在寻找类似的东西:

string rexFormat=@"[^0-9a-zA-Z\.,!+\-* \w ]";
string myInPutString ="what'sup ! my dear friend?";
string replacedString = Regex.Replace(myInPutString, rexFormat, string.Empty);
// will give you whatsup ! my dear friend

删除了特殊字符'?