标签:
1 代码
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Net; 5 using System.Text; 6 using System.Text.RegularExpressions; 7 using System.Threading.Tasks; 8 9 namespace ConsoleApplication7 10 { 11 class Program 12 { 13 static void Main(string[] args) 14 { 15 //检测字符串是否存在两个相邻的数字 16 string regularExpression = "[0-9][0-9]"; 17 Regex rg = new Regex(regularExpression); 18 19 string [] contents = { "01", "12a", "a3", "a33" }; 20 for (int i = 0; i < contents.Length; i++) 21 { 22 if(rg.IsMatch(contents[i])) 23 { 24 Console.WriteLine(contents[i]+"符合正则表达式"); 25 } 26 else 27 { 28 Console.WriteLine(contents[i] + "不符合正则表达式"); 29 30 } 31 } 32 33 Console.ReadKey(); 34 } 35 } 36 }
2 效果
C#正则表达式基础 [0-9][0-9] 检测字符串是否存在两个相邻的数字
标签:
原文地址:http://www.cnblogs.com/jinlingzi/p/5964628.html