Regex to remove all special characters from string?

前端 未结 9 1411
谎友^
谎友^ 2020-12-04 15:15

I\'m completely incapable of regular expressions, and so I need some help with a problem that I think would best be solved by using regular expressions.

I have list

9条回答
  •  南笙
    南笙 (楼主)
    2020-12-04 15:53

    [^a-zA-Z0-9] is a character class matches any non-alphanumeric characters.

    Alternatively, [^\w\d] does the same thing.

    Usage:

    string regExp = "[^\w\d]";
    string tmp = Regex.Replace(n, regExp, "");
    

提交回复
热议问题