Joshua Flanagan has just released library he calls "ReadableRegEx"(I preffer calling it ReadEx) which is basically library that envisions itself to create a more readable(friendlier) RegularExpression code wrapper.
Here's a sample implementation that Joshua posted on his blog:
Suppose we want to check for social security numbers. You might write code like this: Regex socialSecurityNumberCheck = new Regex(@"^\d{3}-?\d{2}-?\d{4}$"); Using ReadableRex (not settled on the name yet...), it would look like: Regex socialSecurityNumberCheck = new Regex(Pattern.With.AtBeginning .Digit.Repeat.Exactly(3) .Literal("-").Repeat.Optional .Digit.Repeat.Exactly(2) .Literal("-").Repeat.Optional .Digit.Repeat.Exactly(4) .AtEnd);
Suppose we want to check for social security numbers. You might write code like this:
Regex socialSecurityNumberCheck = new Regex(@"^\d{3}-?\d{2}-?\d{4}$");
Using ReadableRex (not settled on the name yet...), it would look like:
Regex socialSecurityNumberCheck = new Regex(Pattern.With.AtBeginning
.Digit.Repeat.Exactly(3)
.Literal("-").Repeat.Optional
.Digit.Repeat.Exactly(2)
.Digit.Repeat.Exactly(4)
.AtEnd);
pretty slick huh? Read more about this library here.
Powered by: newtelligence dasBlog 2.3.9074.18820
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.
E-mail
Theme design by Jelle Druyts