in reply to Need to match number other than 1

if ($num =~ /^[^\D1]\d+$/) { print "does not begin with a 1\n"; }

The key to understanding this is that you are looking for anything that is not a non-digit or a 1. When you negate the negations in the above phrase, you'll see that it means you're matching 0, 2-9.

uh, update: that doesn't quite work, hang on a sec...

if ($num =~ /^(?:[^\D1]|1\d)\d*$/) { print "not a 1\n"; }

2nd update: now it works. It is instructive to see how the pattern had to be modified to exclude 1, but allow 10, 19, 1111, ...

• another intruder with the mooring in the heart of the Perl

Replies are listed 'Best First'.
Re^2: Need to match number other than 1
by moritz (Cardinal) on Nov 29, 2007 at 10:40 UTC
    That doesn't match any single digit number, nor will it match 10, which is not 1 either.