in reply to Regex Pattern Problem

After a little playing around, I came up with this:

#!/usr/bin/perl -w use strict; my @stuff = qw(1234 a12345 12345 12345z 123456); foreach my $num (@stuff) { unless ($num =~ /^\d{5,}$/) { print "Not Valid: $num\n"; } else { print "Valid: $num\n"; } }

Note the $ anchor there...this should match any string of digits that's at least 5 digits long, and it will fail for anything with non-digits in it.

EDIT: Removed the extra crap before the $ anchor.

Replies are listed 'Best First'.
Re: Re: Regex Pattern Problem
by THRAK (Monk) on Feb 28, 2001 at 17:49 UTC
    Duh! Thank You. The /^\d{5,}$/ expression works just fine. As I said in my original post, I knew this should be fairly obvious but my brain was stuck in neutral. This meets the criteria of "match any string that consists of 5 or more digits and does not contain any other characters". Lots of other good answers to variations of the problem that may prove useful in the future.
    -THRAK