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 //" [0-9]|[a-z]|[A-Z] ",正则表达式前后有空格的话,不会出现正确结果。不明觉厉 16 string regularExpression = "[0-9]|[a-z]|[A-Z]"; 17 Regex rg = new Regex(regularExpression); 18 19 string contents = "0123456789abcdefgABCDEFG"; 20 for (int i = 0; i < contents.Length; i++) 21 { 22 if(rg.IsMatch(contents[i].ToString())) 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-17 07:18:47