using System; using System.Text.RegularExpressions; namespace Test { class Program { //匹配16进制颜色代码的正则模式 const string pattern = @"[[0-9a-fA-F]{6}]"; const string test1 = "erter[0051e4]terter778t"; const string test2 = "erter[+051e4]terter778t"; static void Main(string[] args) { Regex res = new Regex(pattern); if (res.IsMatch(test1)) { Console.WriteLine("匹配成功"); } else { Console.WriteLine("匹配失败"); } Console.ReadKey(); } } }