Regexp::Common::number -- provide regexes for numbers
use Regexp::Common qw /number/; while (<>) { /^$RE{num}{int}$/ and print "Integer\n"; /^$RE{num}{real}$/ and print "Real\n"; /^$RE{num}{real}{-base => 16}$/ and print "Hexadecimal real\n"; }
Please consult the manual of Regexp::Common for a general description of the works of this interface.
Do not use this module directly, but load it via Regexp::Common.
$RE{num}{int}{-sep}{-group}
Returns a pattern that matches a decimal integer.
If -sep=P is specified, the pattern P is required as a grouping marker within the number.
-sep=P
If -group=N is specified, digits between grouping markers must be grouped in sequences of exactly N characters. The default value of N is 3.
-group=N
For example:
$RE{num}{int} # match 1234567 $RE{num}{int}{-sep=>','} # match 1,234,567 $RE{num}{int}{-sep=>',?'} # match 1234567 or 1,234,567 $RE{num}{int}{-sep=>'.'}{-group=>4} # match 1.2345.6789
Under -keep (see Regexp::Common):
-keep
captures the entire number
captures the optional sign of the number
captures the complete set of digits
$RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon}
Returns a pattern that matches a floating-point number.
If -base=N is specified, the number is assumed to be in that base (with A..Z representing the digits for 11..36). By default, the base is 10.
-base=N
If -radix=P is specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default is qr/[.]/.
-radix=P
qr/[.]/
If -places=N is specified, the number is assumed to have exactly N places after the radix point. If -places=M,N is specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted.
-places=N
-places=M,N
If -sep=P specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed.
If -group=N is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3.
If -expon=P is specified, the pattern P is used as the exponential marker. The default value of P is qr/[Ee]/.
-expon=P
qr/[Ee]/
$RE{num}{real} # matches 123.456 or -0.1234567 $RE{num}{real}{-places=>2} # matches 123.45 or -0.12 $RE{num}{real}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{real}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{real}{-base=>3'} # matches 121.102
Under -keep:
captures the entire match
captures the complete mantissa
captures the whole number portion of the mantissa
captures the radix point
captures the fractional portion of the mantissa
captures the optional exponent marker
captures the entire exponent value
captures the optional sign of the exponent
captures the digits of the exponent
$RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon}
A synonym for $RE{num}{real}{-base=>10}{...}
$RE{num}{real}{-base=>10}{...}
$RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon}
A synonym for $RE{num}{real}{-base=>8}{...}
$RE{num}{real}{-base=>8}{...}
$RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon}
A synonym for $RE{num}{real}{-base=>2}{...}
$RE{num}{real}{-base=>2}{...}
$RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon}
A synonym for $RE{num}{real}{-base=>16}{...}
$RE{num}{real}{-base=>16}{...}
$RE{num}{square}
Returns a pattern that matches a (decimal) square. Regardless whether -keep was set, the matched number will be returned in $1.
$1
This pattern is available for version 5.008 and up.
$RE{num}{roman}
Returns a pattern that matches an integer written in Roman numbers. Case doesn't matter. Only the more modern style, that is, no more than three repetitions of a letter, is recognized. The largest number matched is MMMCMXCIX, or 3999. Larger numbers cannot be expressed using ASCII characters. A future version will be able to deal with the Unicode symbols to match larger Roman numbers.
Under -keep, the number will be captured in $1.
$Log: number.pm,v $ Revision 2.100 2003/01/21 23:19:40 abigail The whole world understands RCS/CVS version numbers, that 1.9 is an older version than 1.10. Except CPAN. Curse the idiot(s) who think that version numbers are floats (in which universe do floats have more than one decimal dot?). Everything is bumped to version 2.100 because CPAN couldn't deal with the fact one file had version 1.10. Revision 1.6 2002/12/27 23:33:15 abigail Roman numbers. Revision 1.5 2002/08/23 13:09:13 abigail Cosmetic POD changes. Revision 1.4 2002/08/23 12:51:26 abigail + Several occurances of 'numbers' changed to 'number'. + Fixed bugs in documentation. + Made example use anchors to make it more clear. (All due to Christopher Baker) Revision 1.3 2002/08/05 12:16:59 abigail Fixed 'Regex::' and 'Rexexp::' typos to 'Regexp::' (Found by Mike Castle). Revision 1.2 2002/07/30 16:37:59 abigail Removed outcommented code. Revision 1.1 2002/07/28 21:41:07 abigail Split off from Regexp::Common.
Regexp::Common for a general description of how to use this interface.
Damian Conway (damian@conway.org)
This package is maintained by Abigail (regexp-common@abigail.nl).
Bound to be plenty.
For a start, there are many common regexes missing. Send them in to regexp-common@abigail.nl.
Copyright (c) 2001 - 2002, Damian Conway. All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License (see http://www.perl.com/perl/misc/Artistic.html)
To install Regexp::Common, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Regexp::Common
CPAN shell
perl -MCPAN -e shell install Regexp::Common
For more information on module installation, please visit the detailed CPAN module installation guide.