SYNOPSIS

    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";
    }

DESCRIPTION

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. Returns a pattern that matches an integer.

If \*(C`-base => B\*(C' is specified, the integer is in base B, with \*(C`2 <= B <= 36\*(C'. For bases larger than 10, upper case letters are used. The default base is 10.

If \*(C`-sep => P\*(C' is specified, the pattern P is required as a grouping marker within the number. If this option is not given, no grouping marker is used.

If \*(C`-group => N\*(C' is specified, digits between grouping markers must be grouped in sequences of exactly N digits. The default value of N is 3. If \*(C`-group => N,M\*(C' is specified, digits between grouping markers must be grouped in sequences of at least N digits, and at most M digits. This option is ignored unless the \*(C`-sep\*(C' option is used.

If \*(C`-places => N\*(C' is specified, the integer recognized must be exactly N digits wide. If \*(C`-places => N,M\*(C' is specified, the integer must be at least N wide, and at most M characters. There is no default, which means that integers are unlimited in size. This option is ignored if the \*(C`-sep\*(C' option is used.

If \*(C`-sign => P\*(C' is used, it's a pattern the leading sign has to match. This defaults to \*(C`[-+]?\*(C', which means the number is optionally preceded by a minus or a plus. If you want to match unsigned integers, use $RE{num}{int}{-sign => ''}.

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 \*(C`-keep\*(C' (see Regexp::Common): captures the entire number captures the optional sign of the number captures the complete set of digits Returns a pattern that matches a floating-point number.

If \*(C`-base=N\*(C' 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.

If \*(C`-radix=P\*(C' is specified, the pattern P is used as the radix point for the number (i.e. the \*(L"decimal point\*(R" in base 10). The default is \*(C`qr/[.]/\*(C'.

If \*(C`-places=N\*(C' is specified, the number is assumed to have exactly N places after the radix point. If \*(C`-places=M,N\*(C' 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.

If \*(C`-sep=P\*(C' 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 \*(C`-group=N\*(C' is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3.

If \*(C`-expon=P\*(C' is specified, the pattern P is used as the exponential marker. The default value of P is \*(C`qr/[Ee]/\*(C'.

If \*(C`-sign=P\*(C' is specified, the pattern P is used to match the leading sign (and the sign of the exponent). This defaults to \*(C`[-+]?\*(C', means means that an optional plus or minus sign can be used.

For example:

$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 \*(C`-keep\*(C': captures the entire match captures the optional sign of the number 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 A synonym for $RE{num}{real}{-base=>10}{...} A synonym for $RE{num}{real}{-base=>8}{...} A synonym for $RE{num}{real}{-base=>2}{...} A synonym for $RE{num}{real}{-base=>16}{...} The same as $RE{num}{real}, except that an exponent isn't allowed. Hence, this returns a pattern matching decimal numbers.

If \*(C`-base=N\*(C' 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.

If \*(C`-radix=P\*(C' is specified, the pattern P is used as the radix point for the number (i.e. the \*(L"decimal point\*(R" in base 10). The default is \*(C`qr/[.]/\*(C'.

If \*(C`-places=N\*(C' is specified, the number is assumed to have exactly N places after the radix point. If \*(C`-places=M,N\*(C' 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.

If \*(C`-sep=P\*(C' 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 \*(C`-group=N\*(C' is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3.

For example:

$RE{num}{decimal} # matches 123.456 or -0.1234567 $RE{num}{decimal}{-places=>2} # matches 123.45 or -0.12 $RE{num}{decimal}{-places=>'0,3'} # matches 123.456 or 0 or 9.8 $RE{num}{decimal}{-sep=>'[,.]?'} # matches 123,456 or 123.456 $RE{num}{decimal}{-base=>3'} # matches 121.102

Under \*(C`-keep\*(C': captures the entire match captures the optional sign of the number captures the complete mantissa captures the whole number portion of the mantissa captures the radix point captures the fractional portion of the mantissa Returns a pattern that matches a (decimal) square. Because Perl's arithmetic is lossy when using integers over about 53 bits, this pattern only recognizes numbers less than 9000000000000000, if one uses a Perl that is configured to use 64 bit integers. Otherwise, the limit is 2147483647. These restrictions were introduced in versions 2.116 and 2.117 of Regexp::Common. Regardless whether \*(C`-keep\*(C' was set, the matched number will be returned in $1.

This pattern is available for version 5.008 and up. 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 \s-1MMMCMXCIX\s0, or 3999. Larger numbers cannot be expressed using \s-1ASCII\s0 characters. A future version will be able to deal with the Unicode symbols to match larger Roman numbers.

Under \*(C`-keep\*(C', the number will be captured in $1.

RELATED TO Regexp::Common::number…

Regexp::Common for a general description of how to use this interface.

AUTHOR

Damian Conway ([email protected])

MAINTAINANCE

This package is maintained by Abigail ([email protected]).

BUGS AND IRRITATIONS

Bound to be plenty.

For a start, there are many common regexes missing. Send them in to [email protected].

LICENSE and COPYRIGHT

This software is Copyright (c) 2001 - 2013, Damian Conway and Abigail.

This module is free software, and maybe used under any of the following licenses:

1) The Perl Artistic License. See the file COPYRIGHT.AL. 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. 3) The BSD Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT.