[ create a new paste ] login | about

Link: http://codepad.org/So7QyMXm    [ raw code | output | fork ]

skeletonkey - Perl, pasted on Feb 22:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
my %tests = (
    '123' => '123',
    'abc123def' => '',
    'abc 123 def' => '123',
    '1 2 4 567' => '567',
    '1 2 4 567 890' => '567',
    '1 2 3 4567 890' => '890',
);

foreach my $s (keys %tests) {
    my ($x) = $s =~ /\b(\d{3})\b/;
    $x ||= ''; # set x to empty string if it is falsy
    print "Test ($s) did not yield the right outcome ($x)\n"
        unless $x eq $tests{$s};
}
print "End of test\n";


Output:
1
End of test


Create a new paste based on this one


Comments: