RegEx to replace special characters in a space with a space? 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"; 
+9
c # regex
source share
3 answers

Full disclosure of the following code:

  • He was not tested
  • I probably messed up the character that slipped into new Regex(...) ;
  • I really don't know C #, but I can use Google for "C# string replace regex" and on MSDN .

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

Here is the correct code:

 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" 

Demo: http://ideone.com/hrKdJ

Also: http://www.regular-expressions.info/

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

Here is java code to replace special characters

 String inputString = "1/10 EP Sp'arrowha?wk XT R;TR 2.4GHz R\\ed"; String re = "[;\\\\/:*?\"<>|&']"; Pattern pattern = Pattern.compile(re); Matcher matcher = pattern.matcher(inputString); String outputString = matcher.replaceAll(" "); 
0
source share

All Articles