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

REFERENCES

148       RFC 1035
149           Mockapetris, P.: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION.
150           November 1987.
151

SEE ALSO

153       Regexp::Common for a general description of how to use this interface.
154

AUTHOR

156       Damian Conway damian@conway.org.
157

MAINTAINANCE

159       This package is maintained by Abigail (regexp-common@abigail.be).
160

BUGS AND IRRITATIONS

162       Bound to be plenty.
163
164       For a start, there are many common regexes missing.  Send them in to
165       regexp-common@abigail.be.
166
168       This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail.
169
170       This module is free software, and maybe used under any of the following
171       licenses:
172
173        1) The Perl Artistic License.     See the file COPYRIGHT.AL.
174        2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
175        3) The BSD Licence.               See the file COPYRIGHT.BSD.
176        4) The MIT Licence.               See the file COPYRIGHT.MIT.
177
178
179
180perl v5.12.0                      2010-01-02            Regexp::Common::net(3)
Impressum