用正则表达式判断含有两个0或者三个0的数字

来源:百度知道 编辑:UC知道 时间:2024/07/16 06:32:53
我想在C#里面判断含有两个0或者三个0的数字,并把这些0用一个0代替,例如:92300021,运行程序后变为,923021,请问我应该怎么做?谢谢!

不用正则也能做阿
strNumber = number.ToString().Replace("000", "00")).Replace("00", "0"));
number = int.Parse(strNumber);

string resultString = null;
stirng subjectString = "92300021";
try {
resultString = Regex.Replace(subjectString, "0+", new MatchEvaluator(ComputeReplacement));
} catch (ArgumentException ex) {
// Syntax error in the regular expression
}

public String ComputeReplacement(Match m) {
// You can vary the replacement text for each match on-the-fly
return "0";
}

javascript 中的是
alert("92300021".replace(/(\d)\1+/gm,"$1"))