Although Millerโs solution fulfills exactly what you requested, fully implement the validation according to the regular expression - I would refuse if I didnโt offer a more robust solution :-) Do not do this with the usual expression!
use strict; use warnings; use Test::More tests => 2; sub match { my $str = shift; if ($str =~ m/ (\d+) , (\d+) /x) { return $1 < $2; } return; } ok(match("(23,36)"), 'should match'); ok(!match("(36,23)"), 'should not match');
It is much clearer, simpler and probably faster!
1..2 ok 1 - should match ok 2 - should not match
source share