Regex::Number::GtLt - generate regex for numbers larger, smaller or between one or two given numbers.
Regex::Number::GtLt
use Regex::Number::GtLt qw/rxgreater rxsmaller rxbetween/; my $gre = rxgreater(6,5000); my $lre = rxsmaller(6,6000); my $bwre = rxbetween(6,5000,6000);
This module exports three function - rxgreater, rxsmaller and rxbetween to generate regex to match numbers greater, smaller or between two given number. First arg for all function is width in decimal positions of expected numbers, second (and third in case of rxbetween) is numbers itself. Numbers to match against generated regexes expected to be zerofilled to specified width, e.g. 100 => 000100 and so on.
use strict; use lib qw!Regex-Number-GtLt/lib!; use Regex::Number::GtLt qw/rxgreater rxsmaller rxbetween/; my $lre = rxsmaller(4,11); my $bwre = rxbetween(4, 555,559); my $gre = rxgreater(4,991); for (map sprintf('%04d',$_), 1..1000){ print "rxgreater match: $_\n" if /$gre/; print "rxsmaller match: $_\n" if /$lre/; print "rxbetween match: $_\n" if /$bwre/; }
This produce following output:
rxsmaller match: 0001 rxsmaller match: 0002 rxsmaller match: 0003 rxsmaller match: 0004 rxsmaller match: 0005 rxsmaller match: 0006 rxsmaller match: 0007 rxsmaller match: 0008 rxsmaller match: 0009 rxsmaller match: 0010 rxbetween match: 0556 rxbetween match: 0557 rxbetween match: 0558 rxgreater match: 0992 rxgreater match: 0993 rxgreater match: 0994 rxgreater match: 0995 rxgreater match: 0996 rxgreater match: 0997 rxgreater match: 0998 rxgreater match: 0999 rxgreater match: 1000
Please note required width of generating regex and using sprintf to format numbers.
Regexp::Common
I.Frolkov, <ifrol@cpan.org>
Copyright (C) 2007 by I.Frolkov
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.
To install Regex::Number::GtLt, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Regex::Number::GtLt
CPAN shell
perl -MCPAN -e shell install Regex::Number::GtLt
For more information on module installation, please visit the detailed CPAN module installation guide.