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

SEE ALSO

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

AUTHOR

202       Damian Conway (damian@conway.org)
203

MAINTAINANCE

205       This package is maintained by Abigail (regexp-common@abigail.be).
206

BUGS AND IRRITATIONS

208       Bound to be plenty.
209
210       For a start, there are many common regexes missing.  Send them in to
211       regexp-common@abigail.be.
212
214       This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail.
215
216       This module is free software, and maybe used under any of the following
217       licenses:
218
219        1) The Perl Artistic License.     See the file COPYRIGHT.AL.
220        2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
221        3) The BSD Licence.               See the file COPYRIGHT.BSD.
222        4) The MIT Licence.               See the file COPYRIGHT.MIT.
223
224
225
226perl v5.12.0                      2010-01-02         Regexp::Common::number(3)
Impressum