我对Regex真的很糟糕,但我想要删除所有这些.,;:''$'@!?/*&^ - +字符串中的字符串
string x = "This is a test string, with lots of: punctuations; in it?!.";
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点 ?
Jos*_* M. 59
首先,请阅读此处了解有关正则表达式的信息.值得学习.
你可以用这个:
Regex.Replace("This is a test string, with lots of: punctuations; in it?!.", @"[^\w\s]", "");
Run Code Online (Sandbox Code Playgroud)
意思是:
[ #Character block start.
^ #Not these characters (letters, numbers).
\w #Word characters.
\s #Space characters.
] #Character block end.
Run Code Online (Sandbox Code Playgroud)
最后它写着"替换任何不是单词字符或空格字符的字符".