2 Mar 2010 21:39
Matching multiple regex patterns simultaneously
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?
Cheers,
Andrey
_______________________________________________ Python-ideas mailing list Python-ideas@... http://mail.python.org/mailman/listinfo/python-ideas
RSS Feed