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}
24
25       Returns a pattern that matches an integer.
26
27       If "-base => B" is specified, the integer is in base B, with "2 <= B <=
28       36". For bases larger than 10, upper case letters are used. The default
29       base is 10.
30
31       If "-sep => P" is specified, the pattern P is required as a grouping
32       marker within the number. If this option is not given, no grouping
33       marker is used.
34
35       If "-group => N" is specified, digits between grouping markers must be
36       grouped in sequences of exactly N digits. The default value of N is 3.
37       If "-group => N,M" is specified, digits between grouping markers must
38       be grouped in sequences of at least N digits, and at most M digits.
39       This option is ignored unless the "-sep" option is used.
40
41       If "-places => N" is specified, the integer recognized must be exactly
42       N digits wide. If "-places => N,M" is specified, the integer must be at
43       least N wide, and at most M characters. There is no default, which
44       means that integers are unlimited in size. This option is ignored if
45       the "-sep" option is used.
46
47       For example:
48
49        $RE{num}{int}                          # match 1234567
50        $RE{num}{int}{-sep=>','}               # match 1,234,567
51        $RE{num}{int}{-sep=>',?'}              # match 1234567 or 1,234,567
52        $RE{num}{int}{-sep=>'.'}{-group=>4}    # match 1.2345.6789
53
54       Under "-keep" (see Regexp::Common):
55
56       $1  captures the entire number
57
58       $2  captures the optional sign of the number
59
60       $3  captures the complete set of digits
61
62       $RE{num}{real}{-base}{-radix}{-places}{-sep}{-group}{-expon}
63
64       Returns a pattern that matches a floating-point number.
65
66       If "-base=N" is specified, the number is assumed to be in that base
67       (with A..Z representing the digits for 11..36). By default, the base is
68       10.
69
70       If "-radix=P" is specified, the pattern P is used as the radix point
71       for the number (i.e. the "decimal point" in base 10). The default is
72       "qr/[.]/".
73
74       If "-places=N" is specified, the number is assumed to have exactly N
75       places after the radix point.  If "-places=M,N" is specified, the num‐
76       ber is assumed to have between M and N places after the radix point.
77       By default, the number of places is unrestricted.
78
79       If "-sep=P" specified, the pattern P is required as a grouping marker
80       within the pre-radix section of the number. By default, no separator is
81       allowed.
82
83       If "-group=N" is specified, digits between grouping separators must be
84       grouped in sequences of exactly N characters. The default value of N is
85       3.
86
87       If "-expon=P" is specified, the pattern P is used as the exponential
88       marker.  The default value of P is "qr/[Ee]/".
89
90       For example:
91
92        $RE{num}{real}                  # matches 123.456 or -0.1234567
93        $RE{num}{real}{-places=>2}      # matches 123.45 or -0.12
94        $RE{num}{real}{-places=>'0,3'}  # matches 123.456 or 0 or 9.8
95        $RE{num}{real}{-sep=>'[,.]?'}   # matches 123,456 or 123.456
96        $RE{num}{real}{-base=>3'}       # matches 121.102
97
98       Under "-keep":
99
100       $1  captures the entire match
101
102       $2  captures the optional sign of the number
103
104       $3  captures the complete mantissa
105
106       $4  captures the whole number portion of the mantissa
107
108       $5  captures the radix point
109
110       $6  captures the fractional portion of the mantissa
111
112       $7  captures the optional exponent marker
113
114       $8  captures the entire exponent value
115
116       $9  captures the optional sign of the exponent
117
118       $10 captures the digits of the exponent
119
120       $RE{num}{dec}{-radix}{-places}{-sep}{-group}{-expon}
121
122       A synonym for $RE{num}{real}{-base=>10}{...}
123
124       $RE{num}{oct}{-radix}{-places}{-sep}{-group}{-expon}
125
126       A synonym for $RE{num}{real}{-base=>8}{...}
127
128       $RE{num}{bin}{-radix}{-places}{-sep}{-group}{-expon}
129
130       A synonym for $RE{num}{real}{-base=>2}{...}
131
132       $RE{num}{hex}{-radix}{-places}{-sep}{-group}{-expon}
133
134       A synonym for $RE{num}{real}{-base=>16}{...}
135
136       $RE{num}{decimal}{-base}{-radix}{-places}{-sep}{-group}
137
138       The same as $RE{num}{real}, except that an exponent isn't allowed.
139       Hence, this returns a pattern matching decimal numbers.
140
141       If "-base=N" is specified, the number is assumed to be in that base
142       (with A..Z representing the digits for 11..36). By default, the base is
143       10.
144
145       If "-radix=P" is specified, the pattern P is used as the radix point
146       for the number (i.e. the "decimal point" in base 10). The default is
147       "qr/[.]/".
148
149       If "-places=N" is specified, the number is assumed to have exactly N
150       places after the radix point.  If "-places=M,N" is specified, the num‐
151       ber is assumed to have between M and N places after the radix point.
152       By default, the number of places is unrestricted.
153
154       If "-sep=P" specified, the pattern P is required as a grouping marker
155       within the pre-radix section of the number. By default, no separator is
156       allowed.
157
158       If "-group=N" is specified, digits between grouping separators must be
159       grouped in sequences of exactly N characters. The default value of N is
160       3.
161
162       For example:
163
164        $RE{num}{decimal}                  # matches 123.456 or -0.1234567
165        $RE{num}{decimal}{-places=>2}      # matches 123.45 or -0.12
166        $RE{num}{decimal}{-places=>'0,3'}  # matches 123.456 or 0 or 9.8
167        $RE{num}{decimal}{-sep=>'[,.]?'}   # matches 123,456 or 123.456
168        $RE{num}{decimal}{-base=>3'}       # matches 121.102
169
170       Under "-keep":
171
172       $1  captures the entire match
173
174       $2  captures the optional sign of the number
175
176       $3  captures the complete mantissa
177
178       $4  captures the whole number portion of the mantissa
179
180       $5  captures the radix point
181
182       $6  captures the fractional portion of the mantissa
183
184       $RE{num}{square}
185
186       Returns a pattern that matches a (decimal) square. Because Perl's
187       arithmetic is lossy when using integers over about 53 bits, this pat‐
188       tern only recognizes numbers less than 9000000000000000, if one uses a
189       Perl that is configured to use 64 bit integers. Otherwise, the limit is
190       2147483647. These restrictions were introduced in versions 2.116 and
191       2.117 of Regexp::Common. Regardless whether "-keep" was set, the
192       matched number will be returned in $1.
193
194       This pattern is available for version 5.008 and up.
195
196       $RE{num}{roman}
197
198       Returns a pattern that matches an integer written in Roman numbers.
199       Case doesn't matter. Only the more modern style, that is, no more than
200       three repetitions of a letter, is recognized. The largest number
201       matched is MMMCMXCIX, or 3999. Larger numbers cannot be expressed using
202       ASCII characters. A future version will be able to deal with the Uni‐
203       code symbols to match larger Roman numbers.
204
205       Under "-keep", the number will be captured in $1.
206

HISTORY

208        $Log: number.pm,v $
209        Revision 2.108  2005/03/16 00:25:58  abigail
210        Added -base, -places for  {num} {int}. Changed -group
211
212        Revision 2.107  2004/12/28 23:45:51  abigail
213        Perl 5.6.2 parses qq lib/Regexp/Common/number.pm{sep}[0-9]! incorrectly
214
215        Revision 2.106  2004/12/28 23:27:58  abigail
216        Replaced C<\d> with [0-9] (Unicode reasons)
217
218        Revision 2.105  2004/07/01 10:11:27  abigail
219        Fixed problems with 32bit integer Perls
220
221        Revision 2.104  2004/06/30 09:14:54  abigail
222        Restricted recognition of square numbers to numbers less than
223        9000000000000000 to avoid round-off errors.
224
225        Revision 2.103  2003/03/12 22:24:25  abigail
226        Decimal numbers
227
228        Revision 2.102  2003/02/10 21:34:24  abigail
229        Added VERSION
230
231        Revision 2.101  2003/02/01 22:55:31  abigail
232        Changed Copyright years
233
234        Revision 2.100  2003/01/21 23:19:40  abigail
235        The whole world understands RCS/CVS version numbers, that 1.9 is an
236        older version than 1.10. Except CPAN. Curse the idiot(s) who think
237        that version numbers are floats (in which universe do floats have
238        more than one decimal dot?).
239        Everything is bumped to version 2.100 because CPAN couldn't deal
240        with the fact one file had version 1.10.
241
242        Revision 1.6  2002/12/27 23:33:15  abigail
243        Roman numbers.
244
245        Revision 1.5  2002/08/23 13:09:13  abigail
246        Cosmetic POD changes.
247
248        Revision 1.4  2002/08/23 12:51:26  abigail
249        + Several occurances of 'numbers' changed to 'number'.
250        + Fixed bugs in documentation.
251        + Made example use anchors to make it more clear.
252         (All due to Christopher Baker)
253
254        Revision 1.3  2002/08/05 12:16:59  abigail
255        Fixed 'Regex::' and 'Rexexp::' typos to 'Regexp::'
256        (Found by Mike Castle).
257
258        Revision 1.2  2002/07/30 16:37:59  abigail
259        Removed outcommented code.
260
261        Revision 1.1  2002/07/28 21:41:07  abigail
262        Split off from Regexp::Common.
263

SEE ALSO

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

AUTHOR

268       Damian Conway (damian@conway.org)
269

MAINTAINANCE

271       This package is maintained by Abigail (regexp-common@abigail.nl).
272

BUGS AND IRRITATIONS

274       Bound to be plenty.
275
276       For a start, there are many common regexes missing.  Send them in to
277       regexp-common@abigail.nl.
278
280            Copyright (c) 2001 - 2003, Damian Conway. All Rights Reserved.
281              This module is free software. It may be used, redistributed
282             and/or modified under the terms of the Perl Artistic License
283                   (see http://www.perl.com/perl/misc/Artistic.html)
284
285
286
287perl v5.8.8                       2003-03-23         Regexp::Common::number(3)
Impressum