IP及Mac地址正则表达式

using System.Text.RegularExpressions;


Mac地址正则:
Regex r = new Regex("[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]:[0-9A-F][0-9A-F]");
if (r.IsMatch("01:02:03:04:05:06))
{
    Console.WriteLine("match");
}


ip正则判断:
Regex r = new Regex(@"^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$");
   string s = "192.168.1.1";
   if (r.IsMatch(s))
   {
    Console.WriteLine("match");
   }   

你可能感兴趣的:(IP及Mac地址正则表达式)