Skip to content

Instantly share code, notes, and snippets.

Created April 28, 2010 14:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/382242 to your computer and use it in GitHub Desktop.
Save anonymous/382242 to your computer and use it in GitHub Desktop.
def _getregex(self):
"""
The RegexObject that is used for finding substrings in the source name
that should be replaced by substitute.
You may set this property either to a RegexObject or to a string. The
latter will automatically be supplied to re.compile().
Defaults to '[A-Za-z0-9.-]'.
"""
return self._regex
def _setregex(self, value):
# Is this the best way to type check value?
if isinstance(value, re._pattern_type):
self._regex = value
elif isinstance(value, str):
self._regex = re.compile(value)
else:
raise TypeError('regex has to be a RegexObject or a string')
regex = property(_getregex, _setregex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment