DevPinoy.org
A Filipino Developers Community
   
Readable Regular Expressions

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);

pretty slick huh? Read more about this library here.


Posted 10-13-2006 12:57 PM by keithrull

Comments

jokiz wrote re: Readable Regular Expressions
on 10-14-2006 4:12 AM

eversince i used NHibernate, i kept seeing this kind of constructs, just like NMock, and now this library...

Copyright DevPinoy 2005-2008