[From nobody Mon Aug 2 21:29:00 2004 Return-Path: <fwp-return-3561-pagaltzis=gmx.de@perl.org> X-Flags: 0000 Delivered-To: GMX delivery to pagaltzis@gmx.de Received: from pop.gmx.net [213.165.64.20] by localhost with POP3 (fetchmail-6.2.5) for ap@localhost (single-drop); Tue, 01 Jun 2004 11:59:37 +0200 (CEST) Received: (qmail 21577 invoked by uid 65534); 1 Jun 2004 09:58:40 -0000 Received: from onion.develooper.com (HELO onion.perl.org) (63.251.223.166) by mx0.gmx.net (mx046) with SMTP; 01 Jun 2004 11:58:40 +0200 Received: (qmail 75939 invoked by uid 1005); 1 Jun 2004 09:58:31 -0000 Mailing-List: contact fwp-help@perl.org; run by ezmlm Precedence: bulk List-Post: <mailto:fwp@perl.org> List-Help: <mailto:fwp-help@perl.org> List-Unsubscribe: <mailto:fwp-unsubscribe@perl.org> List-Subscribe: <mailto:fwp-subscribe@perl.org> Delivered-To: mailing list fwp@perl.org Received: (qmail 75920 invoked from network); 1 Jun 2004 09:58:30 -0000 Delivered-To: fwp@perl.org X-Spam-Status: No, hits=0.0 required=7.0 tests= X-Spam-Check-By: la.mx.develooper.com Subject: Regular expression for years after a given one From: Jose Alves de Castro <jcastro@telbit.pt> To: fwp@perl.org Message-Id: <1086081445.3883.18.camel@localhost.telbit.pt> X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 01 Jun 2004 10:52:55 +0100 X-Spam-Rating: onion.develooper.com 1.6.2 0/1000/N X-GMX-Antivirus: -1 (not scanned, may not use virus scanner) X-GMX-Antispam: 0 (Mail was not recognized as spam) Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=iso-8859-15 Yesterday, a friend of mine was toying around with some Perl code, when he got to a function which would only accept a regular expression. He said: "How can I say that I want every single year after the one I have? It's impossible..." To which I replied: "Nothing is impossible! Especially in Perl! ;-) " (ok, maybe these weren't my words at the time, but they seem cool now, right? :-) ) So after a couple of minutes, this is what I came up with: $year = 2004; # I'm stating it directly to improve clarity $year =~/(\d)(\d)(\d)(\d)/; ($c,$d,$e,$f) = ($4+1,$3+1,$2+1,$1+1); $regex = qr/^\d*(?:${1}${2}${3}[$c-9]|${1}$2[$d-9]\d|$1[$e-9]\d{2}|[$f-9]\d{3})$/; and that does the trick :-) Thought I should share this with you guys :-) Thoughts are welcome :-) BTW: This was made so it would work with $year consisting of four digits... any care to make it generic? :-) Regards, jac -- José Alves de Castro <jcastro@telbit.pt> Telbit - Tecnologias de Informação ]