Regex to match odd numbers

Jasper jaspermccrea at gmail.com
Tue May 27 17:11:30 BST 2014


I'm furiously trying to think of an even stupider way of doing this...


On 27 May 2014 17:09, Jasper <jaspermccrea at gmail.com> wrote:

> From 7 upwards is
>
> ('1' x $foo) =~ /^(11){3,}1$/
>
> or something, I'm not even bothering to test this :S
>
>
> On 27 May 2014 17:08, Jasper <jaspermccrea at gmail.com> wrote:
>
>> Something like the prime regex would work:
>>
>> ('1' x $foo) =~ /^(11)*1$/
>>
>>
>> On 27 May 2014 16:43, Joel Bernstein <joel at fysh.org> wrote:
>>
>>> Surely you only need to examine the right-most digit to know if the
>>> number
>>> is odd? Your special requirement to (AIUI) consider 0..7 as even isn't
>>> difficult to add.
>>>
>>> /joel
>>>
>>>
>>> On 27 May 2014 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?  Obviously it's easy to do in a coupla lines of perl code
>>> > instead of a regex, so I'm asking more out of curiosity than because I
>>> > actually need it.
>>> >
>>> > --
>>> > David Cantrell | Official London Perl Mongers Bad Influence
>>> >
>>> > Today's previously unreported paraphilia is tomorrow's Internet
>>> sensation
>>> >
>>> >
>>>
>>
>>
>>
>> --
>> Jasper
>>
>
>
>
> --
> Jasper
>



-- 
Jasper


More information about the london.pm mailing list