Re: Regular expression for years after a given one
"A. Pagaltzis" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <20040601113742.GA20273@klangraum> |
* Jose Alves de Castro <[email protected]> [2004-06-01 11:59]: > BTW: This was made so it would work with $year consisting of > four digits... any care to make it generic? :-) sub rx_gt { local $_ = shift; return if /\D/; my @alt = ''; for(split //) { $_ .= '\d' for @alt[ 1 .. $#alt ]; if($_ <= 7) { unshift @alt, $alt[0]; $alt[0] .= $_; $alt[1] .= "[@{[ $_+1 ]}-9]"; } elsif($_ == 8) { unshift @alt, $alt[0]; $alt[0] .= 8; $alt[1] .= 9; } else { # == 9 $alt[0] .= 9; } } shift @alt; my $rx = join '|', @alt; return "(?:$rx)"; } $_ = "14987345"; print map "$_\n", "$_:", rx_gt $_; -- Gruss, Aristoteles "Wer nicht über sich selbst lachen kann, nimmt das Leben nicht ernst genug."