shortcut for below regular expression matching even index between 4 to 16

Advertisements

Regex.IsMatch(Source, @"^[0-9a-fA-F]{4}$") || Regex.IsMatch(Source, @"^[0-9a-fA-F]{6}$")||
Regex.IsMatch(Source, @"^[0-9a-fA-F]{8}$") || Regex.IsMatch(Source, @"^[0-9a-fA-F]{10}$") ||
Regex.IsMatch(Source, @"^[0-9a-fA-F]{12}$") || Regex.IsMatch(Source, @"^[0-9a-fA-F]{14}$") ||
Regex.IsMatch(Source, @"^[0-9a-fA-F]{16}$"

can anyone suggest shorcut for the above regex expression matching even index between 4 to 16

>Solution :

You want two to eight pairs of hex digits.

^(?:[0-9a-fA-F]{2}){2,8}$

Leave a Reply Cancel reply