Regex for removing only specific special characters from string

前端 未结 4 1297
梦如初夏
梦如初夏 2021-01-02 16:28

I\'d like to write a regex that would remove the special characters on following basis:

  • To remove white space character
  • @, &
4条回答
  •  情书的邮戳
    2021-01-02 17:03

    use a character set [charsgohere]

    string removableChars = Regex.Escape(@"@&'()<>#");
    string pattern = "[" + removableChars + "]";
    
    string username = Regex.Replace(username, pattern, "");
    

提交回复
热议问题