SPUG: minimal unmatching regex
Michael R. Wolf
MichaelRWolf at att.net
Tue Aug 18 12:04:19 PDT 2009
Question:
What's the smallest (comprehensible) regex that's guaranteed to fail
against all input?
Motivation:
I'm creating a lab for perl classes. I want to provide the stub of a
script that compiles, but always fails to match. Unfortunately, the
obvious minimal RE of // matches *everything*.
Here's a stub of the lab...
# TODO... replace the following line with your regular expression to
match zip codes.
my $zip_re = qr//;
like('98107', $zip_re, 'Simple 5-digit zip'),
like('07748', $zip_re, 'Simple 5-digit zip with leading zero'),
unlike('1234', $zip_re, 'Four digits');
unlike('123456', $zip_re, 'Six digits');
--
Michael R. Wolf
All mammals learn by playing!
MichaelRWolf at att.net
More information about the spug-list
mailing list