grimace: a fluent regular expression generator in Python

Ben Last benlast at
Tue Jul 16 00:21:05 CEST 2013

Hi all

I'd be interested in comments on a fluent regular expression generator I've
been playing with (inspired by the frustrations of a friend of mine who's

The general use case is to be able to construct RE strings such as:

r'^\(\d{3,3}\)-{1,1}\d{3,3}\-{1,1}\d{4,4}$' (intended to match North
American phone number)


from grimace import RE
north_american_number_re = (RE().start


The intent is to provide clarity: since the strings would normally be
generated and compiled when a module is first imported, there's minimal

It's on github at and the first blog
post that explains it is here: (I've
added to it since then).

Tests are the best explanation, and they're in the __init__ at the end so
that they're self-executing if the init is executed.

I'm thinking about other features to implement, and more use cases would be

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list