Geeks With Blogs
Sonam Singh December 2009 Entries
Capturing optional groups in regular expressions?
string input = @"cool man dog no dude yes fight son"; string pattern = @"cool (?<hello>((.)* )) (?<h>( (dude)?)) (?(h)(?<dude>((.)*)))"; MatchCollection matches = Regex.Matches(input, pattern, RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternW... foreach (Match match in matches) { Console.WriteLine("dude=" + match.Groups["dude"].Value); Console.WriteLine("hello=" + match.Groups["hello"].Value); Console.ReadLine(); } /*Output- dude= hello= man dog no dude yes fight ......

Posted On Thursday, December 24, 2009 7:05 AM

Copyright © sonam | Powered by: GeeksWithBlogs.net