Re: Regular expression for years after a given one

"A. Pagaltzis" <[email protected]>
Newsgroups gmane.comp.lang.perl.fun
Message-ID <20040601144702.GB20729@klangraum>
* Winter Christian <[email protected]> [2004-06-01 16:31]:
> Another approach:
> 
> use re 'eval';
> my $re = qr/(\d{4})(??{ $1>$year?'':'x{1000}' })$/;
> 
> Assuming, of course, that $_ never contains a smaller year
> number followed by thousand 'x'es. :-)

You can remove that limitation by replacing 'x{1000}' by '(?!)',
a zero-width negative lookahead, which *always* fails.

Your approach requires multiple regex compilation, too -- the
regex returned by your code is compiled in at run time.

If you do want to go down that route, I'd rather do it like this:

    my $re = qr/(\d{4})(?(?{ $1 <= $year })(?!))/;

which uses a conditional subexpression (?(cond)if-true), where
the condition is a Perl expression (?{ $1 <= $year }), to force
failure using the aforementioned (?!), if the condition is true
(which means I must test for less-than-or-equal, where you test
for greater-than).

-- 
Regards,
Aristotle
 
"If you can't laugh at yourself, you don't take life seriously enough."
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.