我想用每个实例的单个空格替换所有连续的非小写字母字母的所有实例。这行得通,但是为什么要在字母之间插入空格?
const string pattern = @"[^a-z]*";
const string replacement = @" ";
var reg = new Regex(pattern);
string a = "the --fat- cat";
string b = reg.Replace(a, replacement); // b = " t h e f a t c a t " should be "the fat cat"
因为*
(它将前一个令牌重复零次或更多次)。它必须在所有边界中找到一个匹配项,因为所有这些边界中都存在一个空字符串。
const string pattern = @"[^a-z]+";
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句