using System.Text.RegularExpressions;
public static void Main()
string pattern = @"^#([A-F0-9]{3}){1,2}$";
string input = @"Only matches when there are 3 & 6 digits
Only matches if the letters used are: A, B, C, D, E & F
Must use the 'i' flag to match lower & upper case.
RegexOptions options = RegexOptions.IgnoreCase | RegexOptions.Multiline;
foreach (Match m in Regex.Matches(input, pattern, options))
Console.WriteLine("'{0}' found at index {1}.", m.Value, m.Index);