Regexp:...:number(3)
πΈ NAME πΈ
Regexp::Common::number -- provide regexes for numbers.
okay so this is the Regexp::Common::number(3) page from the User Contributed Perl Documentation, and it's literally all about regexes for numbers. π
β¨ 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 π
Bestie, 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. periodt. π
π "$RE{num}{int}{-base}{-sep}{-group}{-places}{-sign}" π
Returns a pattern that matches an integer.
-base => Bβ if specified, the integer is in base B, with2 <= B <= 36. For bases larger than 10, upper case letters are used. The default base is 10.-sep => Pβ if specified, the pattern P is required as a grouping marker within the number. If this option is not given, no grouping marker is used.-group => Nβ if specified, digits between grouping markers must be grouped in sequences of exactly N digits. The default value of N is 3. If-group => N,Mis 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-sepoption is used.-places => Nβ if specified, the integer recognized must be exactly N digits wide. If-places => N,Mis 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-sepoption is used.-sign => Pβ if 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$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 -keep (see Regexp::Common):
$1captures the entire number$2captures the optional sign of the number$3captures the complete set of digits
π¦ "$RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon}" π¦
Returns a pattern that matches a floating-point number.
-base=Nβ if specified, the number is assumed to be in that base (withA..Zrepresenting the digits for11..36). By default, the base is 10.-radix=Pβ if specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default isqr/[.]/.-places=Nβ if specified, the number is assumed to have exactly N places after the radix point. If-places=M,Nis specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted.-sep=Pβ if specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed.-group=Nβ if specified, digits between grouping separators must be grouped in sequences of exactly N characters. The default value of N is 3.-expon=Pβ if specified, the pattern P is used as the exponential marker. The default value of P isqr/[Ee]/.-sign=Pβ if specified, the pattern P is used to match the leading sign (and the sign of the exponent). This defaults to[-+]?, which 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 -keep:
$1captures the entire match$2captures the optional sign of the number$3captures the complete mantissa$4captures the whole number portion of the mantissa$5captures the radix point$6captures the fractional portion of the mantissa$7captures the optional exponent marker$8captures the entire exponent value$9captures the optional sign of the exponent$10captures the digits of the exponent
π "$RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon}" π
A synonym for $RE{num}{real}{-base=>10}{...}
π "$RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon}" π
A synonym for $RE{num}{real}{-base=>8}{...}
π "$RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon}" π
A synonym for $RE{num}{real}{-base=>2}{...}
π§‘ "$RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon}" π§‘
A synonym for $RE{num}{real}{-base=>16}{...}
π "$RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group}" π
The same as $RE{num}{real}, except that an exponent isn't allowed. Hence, this returns a pattern matching decimal numbers.
-base=Nβ if specified, the number is assumed to be in that base (withA..Zrepresenting the digits for11..36). By default, the base is 10.-radix=Pβ if specified, the pattern P is used as the radix point for the number (i.e. the "decimal point" in base 10). The default isqr/[.]/.-places=Nβ if specified, the number is assumed to have exactly N places after the radix point. If-places=M,Nis specified, the number is assumed to have between M and N places after the radix point. By default, the number of places is unrestricted.-sep=Pβ if specified, the pattern P is required as a grouping marker within the pre-radix section of the number. By default, no separator is allowed.-group=Nβ if 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 -keep:
$1captures the entire match$2captures the optional sign of the number$3captures the complete mantissa$4captures the whole number portion of the mantissa$5captures the radix point$6captures 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 -keep was set, the matched number will be returned in $1.
π "$RE{num}{roman}" π
Returns a pattern that matches an integer written in Roman numbers. Case doesn't matter. There is no unique way of writing Roman numerals, but we will not match anything. We require the Roman numerals to list the symbols in order (largest first). The symbols for thousand (M), hundred (C), ten (X), and one (I) can not be repeated more than four times. The symbols for five hundred (D), fifty (L), and five (V) may not appear more than once. A sequence of four repeated characters may also be written as a subtraction: by using the repeated character just once, and have it followed by the symbol which is 5 or 10 as large. So, four can be written as IIII, or as IV, and nine may be written as VIIII or IX. This corresponds to most modern uses of Roman numerals.
The largest number which will be matched is 4999, or MMMMDCCCCLXXXXVIIII, or MMMMCMXCIX.
Under -keep, the number will be captured in $1.
π¦ SEE ALSO π¦
Regexp::Common for a general description of how to use this interface.
π AUTHOR π
Damian Conway (damian@conway.org)
π MAINTENANCE π
This package is maintained by Abigail (regexp-common@abigail.freedom.nl).
π BUGS AND IRRITATIONS π
Bound to be plenty.
For a start, there are many common regexes missing. Send them in to regexp-common@abigail.freedom.nl.
π LICENSE and COPYRIGHT π
This software is Copyright (c) 2001 - 2024, Damian Conway and Abigail.
This module is free software, and maybe used under any of the following licenses:
- The Perl Artistic License. See the file
COPYRIGHT.AL. - The Perl Artistic License 2.0. See the file
COPYRIGHT.AL2. - The BSD License. See the file
COPYRIGHT.BSD. - The MIT License. See the file
COPYRIGHT.MIT.
okay that's the whole Regexp::Common::number(3) page π this one came from perl v5.42.0, dated 2024-08-09 β mwah π bye bestie! πβ¨
π¦ where this page comes from
- opensuse-leap 16.0: perl-Regexp-Common 2024080801.0.0-160000.2.2 Β· Artistic-1.0 OR Artistic-2.0 OR BSD-3-Clause OR MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms