1Regexp::Common::net(3)User Contributed Perl DocumentationRegexp::Common::net(3)
2
3
4

NAME

6       Regexp::Common::net -- provide regexes for IPv4 addresses.
7

SYNOPSIS

9           use Regexp::Common qw /net/;
10
11           while (<>) {
12               /$RE{net}{IPv4}/       and print "Dotted decimal IP address";
13               /$RE{net}{IPv4}{hex}/  and print "Dotted hexadecimal IP address";
14               /$RE{net}{IPv4}{oct}{-sep => ':'}/ and
15                                      print "Colon separated octal IP address";
16               /$RE{net}{IPv4}{bin}/  and print "Dotted binary IP address";
17               /$RE{net}{MAC}/        and print "MAC address";
18               /$RE{net}{MAC}{oct}{-sep => " "}/ and
19                                      print "Space separated octal MAC address";
20           }
21

DESCRIPTION

23       Please consult the manual of Regexp::Common for a general description
24       of the works of this interface.
25
26       Do not use this module directly, but load it via Regexp::Common.
27
28       This modules gives you regular expressions for various style IPv4 and
29       MAC (or ethernet) addresses.
30
31       $RE{net}{IPv4}
32
33       Returns a pattern that matches a valid IP address in "dotted decimal".
34       Note that while 318.99.183.11 is not a valid IP address, it does match
35       "/$RE{net}{IPv4}/", but this is because 318.99.183.11 contains a valid
36       IP address, namely 18.99.183.11. To prevent the unwanted matching, one
37       needs to anchor the regexp: "/^$RE{net}{IPv4}$/".
38
39       For this pattern and the next four, under "-keep" (See Regexp::Common):
40
41       $1  captures the entire match
42
43       $2  captures the first component of the address
44
45       $3  captures the second component of the address
46
47       $4  captures the third component of the address
48
49       $5  captures the final component of the address
50
51       $RE{net}{IPv4}{dec}{-sep}
52
53       Returns a pattern that matches a valid IP address in "dotted decimal"
54
55       If "-sep=P" is specified the pattern P is used as the separator.  By
56       default P is "qr/[.]/".
57
58       $RE{net}{IPv4}{hex}{-sep}
59
60       Returns a pattern that matches a valid IP address in "dotted hexadeci‐
61       mal", with the letters "A" to "F" capitalized.
62
63       If "-sep=P" is specified the pattern P is used as the separator.  By
64       default P is "qr/[.]/". "-sep=""" and "-sep=" "" are useful alterna‐
65       tives.
66
67       $RE{net}{IPv4}{oct}{-sep}
68
69       Returns a pattern that matches a valid IP address in "dotted octal"
70
71       If "-sep=P" is specified the pattern P is used as the separator.  By
72       default P is "qr/[.]/".
73
74       $RE{net}{IPv4}{bin}{-sep}
75
76       Returns a pattern that matches a valid IP address in "dotted binary"
77
78       If "-sep=P" is specified the pattern P is used as the separator.  By
79       default P is "qr/[.]/".
80
81       $RE{net}{MAC}
82
83       Returns a pattern that matches a valid MAC or ethernet address as colon
84       separated hexadecimals.
85
86       For this pattern, and the next four, under "-keep" (See Regexp::Com‐
87       mon):
88
89       $1  captures the entire match
90
91       $2  captures the first component of the address
92
93       $3  captures the second component of the address
94
95       $4  captures the third component of the address
96
97       $5  captures the fourth component of the address
98
99       $6  captures the fifth component of the address
100
101       $7  captures the sixth and final component of the address
102
103       This pattern, and the next four, have a "subs" method as well, which
104       will transform a matching MAC address into so called canonical format.
105       Canonical format means that every component of the address will be
106       exactly two hexadecimals (with a leading zero if necessary), and the
107       components will be separated by a colon.
108
109       The "subs" method will not work for binary MAC addresses if the Perl
110       version predates 5.6.0.
111
112       $RE{net}{MAC}{dec}{-sep}
113
114       Returns a pattern that matches a valid MAC address as colon separated
115       decimals.
116
117       If "-sep=P" is specified the pattern P is used as the separator.  By
118       default P is "qr/:/".
119
120       $RE{net}{MAC}{hex}{-sep}
121
122       Returns a pattern that matches a valid MAC address as colon separated
123       hexadecimals, with the letters "a" to "f" in lower case.
124
125       If "-sep=P" is specified the pattern P is used as the separator.  By
126       default P is "qr/:/".
127
128       $RE{net}{MAC}{oct}{-sep}
129
130       Returns a pattern that matches a valid MAC address as colon separated
131       octals.
132
133       If "-sep=P" is specified the pattern P is used as the separator.  By
134       default P is "qr/:/".
135
136       $RE{net}{MAC}{bin}{-sep}
137
138       Returns a pattern that matches a valid MAC address as colon separated
139       binary numbers.
140
141       If "-sep=P" is specified the pattern P is used as the separator.  By
142       default P is "qr/:/".
143
144       $RE{net}{domain}
145
146       Returns a pattern to match domains (and hosts) as defined in RFC 1035.
147       Under I{-keep} only the entire domain name is returned.
148
149       RFC 1035 says that a single space can be a domainname too. So, the pat‐
150       tern returned by $RE{net}{domain} recognizes a single space as well.
151       This is not always what people want. If you want to recognize domain‐
152       names, but not a space, you can do one of two things, either use
153
154           /(?! )$RE{net}{domain}/
155
156       or use the "{-nospace}" option (without an argument).
157

REFERENCES

159       RFC 1035
160           Mockapetris, P.: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION.
161           November 1987.
162

SEE ALSO

164       Regexp::Common for a general description of how to use this interface.
165

HISTORY

167        $Log: net.pm,v $
168        Revision 2.105  2004/12/28 23:31:54  abigail
169        Replaced C<\d> with [0-9] (Unicode reasons)
170
171        Revision 2.104  2004/06/30 15:11:29  abigail
172        Discuss unwanted matching
173
174        Revision 2.103  2004/06/09 21:47:01  abigail
175        dec/oct greediness
176
177        Revision 2.102  2003/03/12 22:26:35  abigail
178        -nospace switch for domain names
179
180        Revision 2.101  2003/02/01 22:55:31  abigail
181        Changed Copyright years
182
183        Revision 2.100  2003/01/21 23:19:40  abigail
184        The whole world understands RCS/CVS version numbers, that 1.9 is an
185        older version than 1.10. Except CPAN. Curse the idiot(s) who think
186        that version numbers are floats (in which universe do floats have
187        more than one decimal dot?).
188        Everything is bumped to version 2.100 because CPAN couldn't deal
189        with the fact one file had version 1.10.
190
191        Revision 1.8  2003/01/10 11:03:28  abigail
192        Added complete CVS history.
193
194        Revision 1.7  2002/08/05 22:02:06  abigail
195        Typo fix.
196
197        Revision 1.6  2002/08/05 20:36:10  abigail
198        Added $RE{net}{domain}
199
200        Revision 1.5  2002/08/05 12:16:59  abigail
201        Fixed 'Regex::' and 'Rexexp::' typos to 'Regexp::' (Found my Mike Castle).
202
203        Revision 1.4  2002/08/01 10:00:01  abigail
204        Got rid of the split // in the "subs" method of MAC addresses with
205        configurable seperator, as this may lead to incorrect results (for
206        instance, if the separator is the empty string).
207
208        Revision 1.3  2002/07/31 23:27:57  abigail
209        Added regexes for MAC addresses.
210
211        Revision 1.2  2002/07/28 22:57:59  abigail
212        Tests to pinpoint a bug in Regexp::Common's _decache.
213
214        Revision 1.1  2002/07/25 23:53:38  abigail
215        Factored out of Regexp::Common.
216

AUTHOR

218       Damian Conway damian@conway.org.
219

MAINTAINANCE

221       This package is maintained by Abigail (regexp-common@abigail.nl).
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.nl.
228
230        Copyright (c) 2001 - 2004, Damian Conway and Abigail. All Rights Reserved.
231              This module is free software. It may be used, redistributed
232             and/or modified under the terms of the Perl Artistic License
233                   (see http://www.perl.com/perl/misc/Artistic.html)
234
235
236
237perl v5.8.8                       2003-03-23            Regexp::Common::net(3)
Impressum