Readable Regular Expression#

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.

Friday, October 13, 2006 8:56:19 PM (GMT Daylight Time, UTC+01:00) #    Comments [0]  | 

 

Comments are closed.
All content © 2010, Keith Rull
On this page
This site
Calendar
<September 2010>
SunMonTueWedThuFriSat
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
Archives
Sitemap
Blogroll OPML
Disclaimer

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.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts


Pick a theme: