1Regexp::Common::number(U3s)er Contributed Perl DocumentatRieognexp::Common::number(3)
2
3
4

NAME

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

SYNOPSIS

9           use Regexp::Common qw /number/;
10
11           while (<>) {
12               /^$RE{num}{int}$/                and  print "Integer\n";
13               /^$RE{num}{real}$/               and  print "Real\n";
14               /^$RE{num}{real}{-base => 16}$/  and  print "Hexadecimal real\n";
15           }
16

DESCRIPTION

18       Please consult the manual of Regexp::Common for a general description
19       of the works of this interface.
20
21       Do not use this module directly, but load it via Regexp::Common.
22
23   $RE{num}{int}{-base}{-sep}{-group}{-places}{-sign}
24       Returns a pattern that matches an integer.
25
26       If "-base => B" is specified, the integer is in base B, with "2 <= B <=
27       36". For bases larger than 10, upper case letters are used. The default
28       base is 10.
29
30       If "-sep => P" is specified, the pattern P is required as a grouping
31       marker within the number. If this option is not given, no grouping
32       marker is used.
33
34       If "-group => N" is specified, digits between grouping markers must be
35       grouped in sequences of exactly N digits. The default value of N is 3.
36       If "-group => N,M" is specified, digits between grouping markers must
37       be grouped in sequences of at least N digits, and at most M digits.
38       This option is ignored unless the "-sep" option is used.
39
40       If "-places => N" is specified, the integer recognized must be exactly
41       N digits wide. If "-places => N,M" is specified, the integer must be at
42       least N wide, and at most M characters. There is no default, which
43       means that integers are unlimited in size. This option is ignored if
44       the "-sep" option is used.
45
46       If "-sign => P" is used, it's a pattern the leading sign has to match.
47       This defaults to "[-+]?", which means the number is optionally preceded
48       by a minus or a plus. If you want to match unsigned integers, use
49       $RE{num}{int}{-sign => ''}.
50
51       For example:
52
53        $RE{num}{int}                          # match 1234567
54        $RE{num}{int}{-sep=>','}               # match 1,234,567
55        $RE{num}{int}{-sep=>',?'}              # match 1234567 or 1,234,567
56        $RE{num}{int}{-sep=>'.'}{-group=>4}    # match 1.2345.6789
57
58       Under "-keep" (see Regexp::Common):
59
60       $1  captures the entire number
61
62       $2  captures the optional sign of the number
63
64       $3  captures the complete set of digits
65
66   $RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon}
67       Returns a pattern that matches a floating-point number.
68
69       If "-base=N" is specified, the number is assumed to be in that base
70       (with A..Z representing the digits for 11..36). By default, the base is
71       10.
72
73       If "-radix=P" is specified, the pattern P is used as the radix point
74       for the number (i.e. the "decimal point" in base 10). The default is
75       "qr/[.]/".
76
77       If "-places=N" is specified, the number is assumed to have exactly N
78       places after the radix point.  If "-places=M,N" is specified, the
79       number is assumed to have between M and N places after the radix point.
80       By default, the number of places is unrestricted.
81
82       If "-sep=P" specified, the pattern P is required as a grouping marker
83       within the pre-radix section of the number. By default, no separator is
84       allowed.
85
86       If "-group=N" is specified, digits between grouping separators must be
87       grouped in sequences of exactly N characters. The default value of N is
88       3.
89
90       If "-expon=P" is specified, the pattern P is used as the exponential
91       marker.  The default value of P is "qr/[Ee]/".
92
93       If "-sign=P" is specified, the pattern P is used to match the leading
94       sign (and the sign of the exponent). This defaults to "[-+]?", means
95       means that an optional plus or minus sign can be used.
96
97       For example:
98
99        $RE{num}{real}                  # matches 123.456 or -0.1234567
100        $RE{num}{real}{-places=>2}      # matches 123.45 or -0.12
101        $RE{num}{real}{-places=>'0,3'}  # matches 123.456 or 0 or 9.8
102        $RE{num}{real}{-sep=>'[,.]?'}   # matches 123,456 or 123.456
103        $RE{num}{real}{-base=>3'}       # matches 121.102
104
105       Under "-keep":
106
107       $1  captures the entire match
108
109       $2  captures the optional sign of the number
110
111       $3  captures the complete mantissa
112
113       $4  captures the whole number portion of the mantissa
114
115       $5  captures the radix point
116
117       $6  captures the fractional portion of the mantissa
118
119       $7  captures the optional exponent marker
120
121       $8  captures the entire exponent value
122
123       $9  captures the optional sign of the exponent
124
125       $10 captures the digits of the exponent
126
127   $RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon}
128       A synonym for $RE{num}{real}{-base=>10}{...}
129
130   $RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon}
131       A synonym for $RE{num}{real}{-base=>8}{...}
132
133   $RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon}
134       A synonym for $RE{num}{real}{-base=>2}{...}
135
136   $RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon}
137       A synonym for $RE{num}{real}{-base=>16}{...}
138
139   $RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group}
140       The same as $RE{num}{real}, except that an exponent isn't allowed.
141       Hence, this returns a pattern matching decimal numbers.
142
143       If "-base=N" is specified, the number is assumed to be in that base
144       (with A..Z representing the digits for 11..36). By default, the base is
145       10.
146
147       If "-radix=P" is specified, the pattern P is used as the radix point
148       for the number (i.e. the "decimal point" in base 10). The default is
149       "qr/[.]/".
150
151       If "-places=N" is specified, the number is assumed to have exactly N
152       places after the radix point.  If "-places=M,N" is specified, the
153       number is assumed to have between M and N places after the radix point.
154       By default, the number of places is unrestricted.
155
156       If "-sep=P" specified, the pattern P is required as a grouping marker
157       within the pre-radix section of the number. By default, no separator is
158       allowed.
159
160       If "-group=N" is specified, digits between grouping separators must be
161       grouped in sequences of exactly N characters. The default value of N is
162       3.
163
164       For example:
165
166        $RE{num}{decimal}                  # matches 123.456 or -0.1234567
167        $RE{num}{decimal}{-places=>2}      # matches 123.45 or -0.12
168        $RE{num}{decimal}{-places=>'0,3'}  # matches 123.456 or 0 or 9.8
169        $RE{num}{decimal}{-sep=>'[,.]?'}   # matches 123,456 or 123.456
170        $RE{num}{decimal}{-base=>3'}       # matches 121.102
171
172       Under "-keep":
173
174       $1  captures the entire match
175
176       $2  captures the optional sign of the number
177
178       $3  captures the complete mantissa
179
180       $4  captures the whole number portion of the mantissa
181
182       $5  captures the radix point
183
184       $6  captures the fractional portion of the mantissa
185
186   $RE{num}{square}
187       Returns a pattern that matches a (decimal) square. Because Perl's
188       arithmetic is lossy when using integers over about 53 bits, this
189       pattern only recognizes numbers less than 9000000000000000, if one uses
190       a Perl that is configured to use 64 bit integers. Otherwise, the limit
191       is 2147483647. These restrictions were introduced in versions 2.116 and
192       2.117 of Regexp::Common. Regardless whether "-keep" was set, the
193       matched number will be returned in $1.
194
195   $RE{num}{roman}
196       Returns a pattern that matches an integer written in Roman numbers.
197       Case doesn't matter. There is no unique way of writing Roman numerals,
198       but we will not match anything. We require the Roman numerals to list
199       the symbols in order (largest first). The symbols for thousand ("M"),
200       hundred ("C"), ten ("X"), and one ("I") can not be repeated more than
201       four times. The symbols for five hundred ("D"), fifty ("L"), and five
202       ("V") may not appear more than once. A sequence of four repeated
203       characters may also be written as a subtraction: by using the repeated
204       character just once, and have it followed by the symbol which is 5 or
205       10 as large. So, four can be written as "IIII", or as "IV", and nine
206       may be written as "VIIII" or "IX". This corresponds to most modern uses
207       of Roman numerals.
208
209       The largest number which will be matched is 4999, or
210       "MMMMDCCCCLXXXXVIIII", or "MMMMCMXCIX".
211
212       Under "-keep", the number will be captured in $1.
213

SEE ALSO

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

AUTHOR

218       Damian Conway (damian@conway.org)
219

MAINTENANCE

221       This package is maintained by Abigail (regexp-common@abigail.be).
222

BUGS AND IRRITATIONS

224       Bound to be plenty.
225
226       For a start, there are many common regexes missing.  Send them in to
227       regexp-common@abigail.be.
228
230       This software is Copyright (c) 2001 - 2017, Damian Conway and Abigail.
231
232       This module is free software, and maybe used under any of the following
233       licenses:
234
235        1) The Perl Artistic License.     See the file COPYRIGHT.AL.
236        2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
237        3) The BSD License.               See the file COPYRIGHT.BSD.
238        4) The MIT License.               See the file COPYRIGHT.MIT.
239
240
241
242perl v5.36.0                      2022-07-22         Regexp::Common::number(3)
Impressum