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 = "([a-z]|[A-Z])([a-z]|[A-Z])"; 17 Regex rg = new Regex(regularExpression); 18 19 string [] contents = { "01", "12aa", "a3bb", "a3b3" }; 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 效果
时间: 2024-10-16 07:37:59