RegEx用空格替换字符串中的特殊字符? asp.net c#

string inputString = "1/10 EP Sp'arrowha?wk XT R;TR 2.4GHz Red"; //Characters Collection: (';', '\', '/', ':', '*', '?', ' " ', '', '|', '&', ''') string outputString = "1 10 EP Sp arrowha wk XT R TR 2.4GHz Red"; 

关于以下代码的完整披露:

  • 它没有经过测试
  • 我可能搞砸了new Regex(...)逃脱的角色new Regex(...) ;
  • 我实际上并不知道C#,但我可以谷歌"C# string replace regex"并登陆MSDN

     Regex re = new Regex("[;\\/:*?\"<>|&']"); string outputString = re.Replace(inputString, " "); 

这是正确的代码:

 string inputString = "1/10 EP Sp'arrowha?wk XT R;TR 2.4GHz R\\ed"; Regex re = new Regex("[;\\\\/:*?\"<>|&']"); string outputString = re.Replace(inputString, " "); // outputString is "1 10 EP Sp arrowha wk XT R TR 2.4GHz R ed" 

演示: http : //ideone.com/hrKdJ

另外: http : //www.regular-expressions.info/

 string outputString = Regex.Replace(inputString,"[;\/:*?""<>|&']",String.Empty)