Mega Code Archive

 
Categories / C# Book / 11 Regular Expression Basics
 

0659 Matching a Guid

using System; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { string r = @"(?i)\b" + @"[0-9a-fA-F]{8}\-" + @"[0-9a-fA-F]{4}\-" + @"[0-9a-fA-F]{4}\-" + @"[0-9a-fA-F]{4}\-" + @"[0-9a-fA-F]{12}" + @"\b"; string text = "Its key is {11250410-fFff-ffD3-fA0C-0f0fEffCff01}."; Console.WriteLine (Regex.Match (text, r).Index); } } The output: 12