Your question is a perfect example of why you should provide a working example when asking questions on SOPW
I'm assuming you're doing something like this...
If that assumption is correct, then as already mentioned, your single digit numbers are not passing your regex because you've mandated that there must be two characters.my @test_numbers = qw(1 2 5 8 10 12 14 56); foreach my $test_number (@test_numbers) { if( $test_number =~ /^\d{2}$/){ if($test_number <= 10){ print "$test_number\n"; } } }
this is a simple fix to the regex, combined with getting rid of your nested if statement you get the following.
but without knowing exactly what your data was, it's hard to say if this is right for you.foreach my $test_number (@test_numbers) { if( $test_number =~ /^\d{1,2}$/ and $test_number <= 10){ print "$test_number\n"; } } __OUTPUT__ 1 2 5 8 10
In reply to Re: vallidating a regular expression
by reasonablekeith
in thread vallidating a regular expression
by s_gaurav1091
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |