[英]How I can check a string with Regular expressions about the string has 12 characters and contains 0-9a-f?
I want to check a string with Regex whether the string has 12 characters and this contain af and 0-9. 我想用正则表达式检查一个字符串,该字符串是否包含12个字符,并且包含af和0-9。
Here my code: 这是我的代码:
mac = "000475af588c"; //12 Characters
Match match = Regex.Match(mac, @"([A-Fa-f0-9]+)");
if (match.Success)
{
//todo
}
Use {12}
around your character class []
to make it 12 在您的角色类[]
周围使用{12}
使其变为12
Match match = Regex.Match(mac, @"^([A-Fa-f0-9]{12})$");
Alternately you can use case insensitive option as well: 另外,您也可以使用不区分大小写的选项:
Match match = Regex.Match(mac, @"^([a-f0-9]{12})$", RegexOptions.IgnoreCase);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.