Regular expression guaranteed to fail
Jeremy Bowers
jerf at jerf.org
Fri Aug 20 16:10:22 EDT 2004
On Fri, 20 Aug 2004 10:35:18 +0000, Des Small wrote:
> The question is, what regular expression should correspond to the
> empty set?
I would return compiled RE objects instead of strings, and in the empty
case, return a class you write that matches the interface of a compiled RE
but returns what you like. Something like:
def NeverMatch(object):
def match(*args, **kwargs):
return None
def set2re(s):
if s: return re.compile("|".join([e for e in s]))
else: return NeverMatch()
More information about the Python-list
mailing list