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