OUTPUT:use strict; use warnings; use Test::Simple qw(no_plan); my %test_cases = ( ' 999' => 'valid', ' 9999' => 'valid', '999999' => 'valid', ' 9' => 'valid', ' 99 9' => 'invalid', ); foreach my $case (keys %test_cases) { my $does_match = $case =~ / ^\s* # any number of leading spaces \d+ # followed by a number of digits (:? [^\s]* # but cant have any spaces after a digit has b +een found \d+ # It must contain at least one digit at the en +d )?$ /x ; ok( !($does_match xor $test_cases{$case} eq 'valid'), "'$case': $test_cases{$case}" ); }
ok 1 - '999999': valid ok 2 - ' 999': valid ok 3 - ' 9': valid ok 4 - ' 9999': valid ok 5 - ' 99 9': invalid 1..5
In reply to Re: Should be a simple spaces/digits regex....but I'm turning grey!
by BillKSmith
in thread Should be a simple spaces/digits regex....but I'm turning grey!
by viffer
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |