Regex to match odd numbers

Mike Whitaker mike at altrion.org
Tue May 27 16:57:59 BST 2014


On 27 May 2014, at 16:22, David Cantrell <david at cantrell.org.uk> wrote:

> As part of the nasty mess that is CPANdeps, I have this line of code:
> 
> $record->{is_dev_perl} = (
> $record->{perl} =~ /(^5\.(7|9|11|13|15|17|19|21)|rc|patch)/i
> ) ? 1 : 0;
> 
> I'd like to not have to remember to add 23 to the list in a year or so's
> time. Can anyone think of a nice way of matching any odd number from 7
> upwards?

I may be sufficiently uncaffinated this late on a logical Monday to be missing something, but how about:

$record->{perl} =~ /(^5\.(7|9|(\d+[13579])|rc|patch)/i

which should be good for a while




More information about the london.pm mailing list