C#交互窗口内使用:
1. 是否为double
> using System.Text.RegularExpressions; > bool isMatch = Regex.IsMatch("652",@"^d{6}$"); > Console.Write(isMatch); False > bool isMatch = Regex.IsMatch("476800",@"^d{6}$"); > Console.Write(isMatch); True Regex RegNumber = new Regex("^[0-9]+(\.[0-9]+)?$"); // 判断是否为double
2. 判断 0-100 正整数
[TestMethod] public void TestMethod1() { // /^(0|[1-9]d|100)$/ string regexString = "^(100|[1-9]\d|\d)$"; for (int i = 0; i < 100; i++) { Assert.AreEqual(true,Regex.IsMatch(i.ToString(),regexString)); } Assert.AreEqual(false, Regex.IsMatch("-1", regexString)); Assert.AreEqual(false, Regex.IsMatch("-01", regexString)); Assert.AreEqual(false, Regex.IsMatch("-10", regexString)); Assert.AreEqual(false, Regex.IsMatch("-100", regexString)); Assert.AreEqual(false, Regex.IsMatch("101", regexString)); Assert.AreEqual(false, Regex.IsMatch("20.6", regexString)); Assert.AreEqual(false, Regex.IsMatch("99.99", regexString)); Assert.AreEqual(false, Regex.IsMatch("0.99", regexString)); Assert.AreEqual(false, Regex.IsMatch("1001", regexString)); Assert.AreEqual(false, Regex.IsMatch("10001", regexString)); }