【发布时间】:2019-08-16 09:27:33
【问题描述】:
我试图弄清楚,如何在字符串中只允许单一类型的标记。例如,如果字符串inputStr 包含不同的标记:
string inputStr = "hello, how are you? ~ say something: what's up? hi... tell me. what?! ok: so,";
这样:
string outputStr = Regex.Replace(inputStr, @"[^\w\s]", "");
结果我会得到没有任何标记的outputStr:
hello how are you say something whatsup hi tell me what ok so
想要得到想要的结果,我只想在outputStr 中保留单个特定冒号":" 标记:
hello how are you say something: whatsup hi tell me what ok: so
任何指南、建议或示例都会有所帮助
【问题讨论】: