Carl Nolan’s ramblings on development
In a recent post I talked about using String.forall for string matching over the use of Regex:
http://blogs.msdn.com/b/carlnol/archive/2011/10/20/f-string-extension-methods-rather-than-using-regex.aspx
I do however use Regex a lot for other types of processing. One thing I find myself doing a bit is capturing values from a Match. If you find yourself doing this a lot the Dynamic Lookup Operator allows one to define a simple model for extracting the captured group values:
The outcome of this code is:
The RegexCatcher type is a simple type that enables one to initialize a Regex, with an associated search string, and then providing access the captured groups:
Although the pattern is simple, I hope one will agree, that the code using this type is very succinct and easy to read.