Created
September 15, 2008 18:30
-
-
Save jeremyBanks/10904 to your computer and use it in GitHub Desktop.
A simple class to cache previously-compiled regular expressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# encoding: utf-8 | |
import re | |
class reCache(object): | |
def __init__(self): | |
self.cache = {} | |
def getPattern(self, pattern, flags=0): | |
try: | |
return self.cache[pattern, flags] | |
except KeyError: | |
self.cache[pattern, flags] = compiled = re.compile(pattern, flags) | |
return compiled | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment