[Python-ideas] Matching multiple regex patterns simultaneously

Andrey Fedorov anfedorov at gmail.com
Tue Mar 2 21:39:57 CET 2010

So a couple of libraries (Django being the most popular that comes to mind)
try to match a string against several regex expressions. I'm wondering if
there exists a library to "merge" multiple compiled regex expressions into a
single lookup. This could be exposed in a interface like:


So for an example:

rd = ReDict()

rd['^foo$'] = 1
rd['^bar*$'] = 2
rd['^bar$'] = 3

assert rd['foo'] == [1]
assert rd['barrrr'] == [2]
assert rd['bar'] == [2,3]

The naive implementation I link is obviously inefficient. What would be the
easiest way to go about compiling a set of regex-es together, so that they
can be matched against a string at the same time? Are there any standard
libraries that do this I'm not aware of?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20100302/f8016a57/attachment.html>

More information about the Python-ideas mailing list