Codex

Regexp::Common::number

Section: User Contributed Perl Documentation (3pm)

Updated: 2013-03-11

Index?action=index Return to Main Contents


NAME

Regexp::Common::number -- provide regexes for numbers

SYNOPSIS

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.

$RE{num}{int}{-base}{-sep}{-group}{-places}{-sign}

Returns a pattern that matches an integer.

If B is specified, the integer is in base B, with B . For bases larger than 10, upper case letters are used. The default base is 10.
If P 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 N is specified, digits between grouping markers must be grouped in sequences of exactly N digits. The default value of N is 3. If N,M 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 option is used.
If N is specified, the integer recognized must be exactly N digits wide. If N,M 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 option is used.
If P is used, it's a pattern the leading sign has to match. This defaults to , which means the number is optionally preceded by a minus or a plus. If you want to match unsigned integers, use .

For example:

Under (see Regexp::Common):
$1
captures the entire number:
$2
captures the optional sign of the number:
$3
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 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.
If 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 .
If N is specified, the number is assumed to have exactly N places after the radix point. If 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.
If 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 N is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3.
If P is specified, the pattern P is used as the exponential marker. The default value of P is .
If P is specified, the pattern P is used to match the leading sign (and the sign of the exponent). This defaults to , means means that an optional plus or minus sign can be used.

For example:

Under :
$1
captures the entire match:
$2
captures the optional sign of the number:
$3
captures the complete mantissa:
$4
captures the whole number portion of the mantissa:
$5
captures the radix point:
$6
captures the fractional portion of the mantissa:
$7
captures the optional exponent marker:
$8
captures the entire exponent value:
$9
captures the optional sign of the exponent:
$10
captures the digits of the exponent:

$RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon}

A synonym for

$RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon}

A synonym for

$RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon}

A synonym for

$RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon}

A synonym for

$RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group}

The same as , except that an exponent isn't allowed. Hence, this returns a pattern matching decimal numbers.
If 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.
If 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 .
If N is specified, the number is assumed to have exactly N places after the radix point. If 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.
If 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 N is specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3.

For example:

Under :
$1
captures the entire match:
$2
captures the optional sign of the number:
$3
captures the complete mantissa:
$4
captures the whole number portion of the mantissa:
$5
captures the radix point:
$6
captures the fractional portion of the mantissa:

$RE{num}{square}

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 was set, the matched number will be returned in .

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 , the number will be captured in .

SEE ALSO

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:


Index

NAME

SYNOPSIS

DESCRIPTION

$RE{num}{int}{-base}{-sep}{-group}{-places}{-sign}

$RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon}

$RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon}

$RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon}

$RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon}

$RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon}

$RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group}

$RE{num}{square}

$RE{num}{roman}

SEE ALSO

AUTHOR

MAINTAINANCE

BUGS AND IRRITATIONS

LICENSE and COPYRIGHT