簡體   English   中英

我如何用正則表達式檢查字符串,該字符串包含12個字符並包含0-9a-f?

[英]How I can check a string with Regular expressions about the string has 12 characters and contains 0-9a-f?

我想用正則表達式檢查一個字符串,該字符串是否包含12個字符,並且包含af和0-9。

這是我的代碼:

mac = "000475af588c"; //12 Characters
Match match = Regex.Match(mac, @"([A-Fa-f0-9]+)");

if (match.Success)
{
    //todo
}

在您的角色類[]周圍使用{12}使其變為12

Match match = Regex.Match(mac, @"^([A-Fa-f0-9]{12})$");

另外,您也可以使用不區分大小寫的選項:

Match match = Regex.Match(mac, @"^([a-f0-9]{12})$", RegexOptions.IgnoreCase);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM