in reply to Match range of number
use strict; use warnings; my @toTest = qw{ X-1Y40 X13Y39 X20Y60 X22Y35 }; my $rxValid = do { local $" = q{|}; my @xRange = ( 0 .. 22 ); my @yRange = ( 35 .. 50 ); qr{(?x) ^ X (?:@xRange) Y (?:@yRange) $}; }; foreach my $test ( @toTest ) { print qq{$test: }, $test =~ $rxValid ? qq{valid\n} : qq{invalid\n}; }
This produces the following.
X-1Y40: invalid X13Y39: valid X20Y60: invalid X22Y35: valid
I hope this is helpful.
Cheers,
JohnGG
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Match range of number
by ikegami (Patriarch) on Nov 15, 2007 at 11:56 UTC | |
by andreas1234567 (Vicar) on Nov 15, 2007 at 12:25 UTC |