Created
December 8, 2013 12:20
-
-
Save reyjrar/7856658 to your computer and use it in GitHub Desktop.
Testing variations on matching digits with Perl Regex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# | |
use strict; | |
use warnings; | |
use Benchmark qw(cmpthese); | |
my @tests = ( | |
q{testing 12345 some more stuff}, | |
q{123 testing some stuff}, | |
q{this is a really long sentence which is intentionally not giving you a number, so don't even try, it's not going to happen.}, | |
q{this is another long string. I promise you at the end there will be a number, but I'm not going to let you have it right now. Ok, Now. 1}, | |
); | |
my %RE = ( | |
n => qr/[0-9]+/, | |
d => qr/\d+/, | |
); | |
cmpthese(500_000, { | |
'using \d' => sub { /$RE{d}/ for @tests }, | |
'using \d with o' => sub { /$RE{d}/o for @tests }, | |
'using \d with a' => sub { /$RE{d}/a for @tests }, | |
'using [0-9]' => sub { /$RE{n}/ for @tests }, | |
'using [0-9] with o' => sub { /$RE{n}/o for @tests }, | |
}); |
Author
reyjrar
commented
Dec 8, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment