.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Regexp::Common::net 3pm" .TH Regexp::Common::net 3pm "2022-10-15" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Regexp::Common::net \-\- provide regexes for IPv4, IPv6, and MAC addresses. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Regexp::Common qw /net/; \& \& while (<>) { \& /$RE{net}{IPv4}/ and print "Dotted decimal IP address"; \& /$RE{net}{IPv4}{hex}/ and print "Dotted hexadecimal IP address"; \& /$RE{net}{IPv4}{oct}{\-sep => \*(Aq:\*(Aq}/ and \& print "Colon separated octal IP address"; \& /$RE{net}{IPv4}{bin}/ and print "Dotted binary IP address"; \& /$RE{net}{MAC}/ and print "MAC address"; \& /$RE{net}{MAC}{oct}{\-sep => " "}/ and \& print "Space separated octal MAC address"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Please consult the manual of Regexp::Common for a general description of the works of this interface. .PP Do not use this module directly, but load it via \fIRegexp::Common\fR. .PP This modules gives you regular expressions for various style IPv4, IPv6, and \s-1MAC\s0 (or ethernet) addresses. .ie n .SS "$RE{net}{IPv4}" .el .SS "\f(CW$RE{net}{IPv4}\fP" .IX Subsection "$RE{net}{IPv4}" Returns a pattern that matches a valid \s-1IP\s0 address in \*(L"dotted decimal\*(R". Note that while \f(CW318.99.183.11\fR is not a valid \s-1IP\s0 address, it does match \f(CW\*(C`/$RE{net}{IPv4}/\*(C'\fR, but this is because \f(CW318.99.183.11\fR contains a valid \s-1IP\s0 address, namely \f(CW18.99.183.11\fR. To prevent the unwanted matching, one needs to anchor the regexp: \f(CW\*(C`/^$RE{net}{IPv4}$/\*(C'\fR. .PP For this pattern and the next four, under \f(CW\*(C`\-keep\*(C'\fR (See Regexp::Common): .ie n .IP "$1" 4 .el .IP "\f(CW$1\fR" 4 .IX Item "$1" captures the entire match .ie n .IP "$2" 4 .el .IP "\f(CW$2\fR" 4 .IX Item "$2" captures the first component of the address .ie n .IP "$3" 4 .el .IP "\f(CW$3\fR" 4 .IX Item "$3" captures the second component of the address .ie n .IP "$4" 4 .el .IP "\f(CW$4\fR" 4 .IX Item "$4" captures the third component of the address .ie n .IP "$5" 4 .el .IP "\f(CW$5\fR" 4 .IX Item "$5" captures the final component of the address .ie n .SS "$RE{net}{IPv4}{dec}{\-sep}" .el .SS "\f(CW$RE{net}{IPv4}{dec}{\-sep}\fP" .IX Subsection "$RE{net}{IPv4}{dec}{-sep}" Returns a pattern that matches a valid \s-1IP\s0 address in \*(L"dotted decimal\*(R". Leading 0s are allowed, as long as each component does not exceed 3 digits. .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/[.]/\*(C'\fR. .ie n .SS "$RE{net}{IPv4}{strict}{\-sep}" .el .SS "\f(CW$RE{net}{IPv4}{strict}{\-sep}\fP" .IX Subsection "$RE{net}{IPv4}{strict}{-sep}" Returns a pattern that matches a valid \s-1IP\s0 address in \*(L"dotted decimal\*(R", but disallow any leading 0s. .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/[.]/\*(C'\fR. .ie n .SS "$RE{net}{IPv4}{hex}{\-sep}" .el .SS "\f(CW$RE{net}{IPv4}{hex}{\-sep}\fP" .IX Subsection "$RE{net}{IPv4}{hex}{-sep}" Returns a pattern that matches a valid \s-1IP\s0 address in \*(L"dotted hexadecimal\*(R", with the letters \f(CW\*(C`A\*(C'\fR to \f(CW\*(C`F\*(C'\fR capitalized. .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/[.]/\*(C'\fR. \f(CW\*(C`\-sep=""\*(C'\fR and \&\f(CW\*(C`\-sep=" "\*(C'\fR are useful alternatives. .ie n .SS "$RE{net}{IPv4}{oct}{\-sep}" .el .SS "\f(CW$RE{net}{IPv4}{oct}{\-sep}\fP" .IX Subsection "$RE{net}{IPv4}{oct}{-sep}" Returns a pattern that matches a valid \s-1IP\s0 address in \*(L"dotted octal\*(R" .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/[.]/\*(C'\fR. .ie n .SS "$RE{net}{IPv4}{bin}{\-sep}" .el .SS "\f(CW$RE{net}{IPv4}{bin}{\-sep}\fP" .IX Subsection "$RE{net}{IPv4}{bin}{-sep}" Returns a pattern that matches a valid \s-1IP\s0 address in \*(L"dotted binary\*(R" .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/[.]/\*(C'\fR. .ie n .SS "$RE{net}{MAC}" .el .SS "\f(CW$RE{net}{MAC}\fP" .IX Subsection "$RE{net}{MAC}" Returns a pattern that matches a valid \s-1MAC\s0 or ethernet address as colon separated hexadecimals. .PP For this pattern, and the next four, under \f(CW\*(C`\-keep\*(C'\fR (See Regexp::Common): .ie n .IP "$1" 4 .el .IP "\f(CW$1\fR" 4 .IX Item "$1" captures the entire match .ie n .IP "$2" 4 .el .IP "\f(CW$2\fR" 4 .IX Item "$2" captures the first component of the address .ie n .IP "$3" 4 .el .IP "\f(CW$3\fR" 4 .IX Item "$3" captures the second component of the address .ie n .IP "$4" 4 .el .IP "\f(CW$4\fR" 4 .IX Item "$4" captures the third component of the address .ie n .IP "$5" 4 .el .IP "\f(CW$5\fR" 4 .IX Item "$5" captures the fourth component of the address .ie n .IP "$6" 4 .el .IP "\f(CW$6\fR" 4 .IX Item "$6" captures the fifth component of the address .ie n .IP "$7" 4 .el .IP "\f(CW$7\fR" 4 .IX Item "$7" captures the sixth and final component of the address .PP This pattern, and the next four, have a \f(CW\*(C`subs\*(C'\fR method as well, which will transform a matching \s-1MAC\s0 address into so called canonical format. Canonical format means that every component of the address will be exactly two hexadecimals (with a leading zero if necessary), and the components will be separated by a colon. .ie n .SS "$RE{net}{MAC}{dec}{\-sep}" .el .SS "\f(CW$RE{net}{MAC}{dec}{\-sep}\fP" .IX Subsection "$RE{net}{MAC}{dec}{-sep}" Returns a pattern that matches a valid \s-1MAC\s0 address as colon separated decimals. .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/:/\*(C'\fR. .ie n .SS "$RE{net}{MAC}{hex}{\-sep}" .el .SS "\f(CW$RE{net}{MAC}{hex}{\-sep}\fP" .IX Subsection "$RE{net}{MAC}{hex}{-sep}" Returns a pattern that matches a valid \s-1MAC\s0 address as colon separated hexadecimals, with the letters \f(CW\*(C`a\*(C'\fR to \f(CW\*(C`f\*(C'\fR in lower case. .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/:/\*(C'\fR. .ie n .SS "$RE{net}{MAC}{oct}{\-sep}" .el .SS "\f(CW$RE{net}{MAC}{oct}{\-sep}\fP" .IX Subsection "$RE{net}{MAC}{oct}{-sep}" Returns a pattern that matches a valid \s-1MAC\s0 address as colon separated octals. .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/:/\*(C'\fR. .ie n .SS "$RE{net}{MAC}{bin}{\-sep}" .el .SS "\f(CW$RE{net}{MAC}{bin}{\-sep}\fP" .IX Subsection "$RE{net}{MAC}{bin}{-sep}" Returns a pattern that matches a valid \s-1MAC\s0 address as colon separated binary numbers. .PP If \f(CW\*(C`\-sep=\f(CIP\f(CW\*(C'\fR is specified the pattern \fIP\fR is used as the separator. By default \fIP\fR is \f(CW\*(C`qr/:/\*(C'\fR. .ie n .SS "$RE{net}{IPv6}{\-sep => \*(Aq:\*(Aq}{\-style => \*(AqHeX\*(Aq}" .el .SS "\f(CW$RE{net}{IPv6}{\-sep => \*(Aq:\*(Aq}{\-style => \*(AqHeX\*(Aq}\fP" .IX Subsection "$RE{net}{IPv6}{-sep => :}{-style => HeX}" Returns a pattern matching IPv6 numbers. An IPv6 address consists of eight groups of four hexadecimal digits, separated by colons. In each group, leading zeros may be omitted. Two or more consecutive groups consisting of only zeros may be omitted (including any colons separating them), resulting into two sets of groups, separated by a double colon. (Each of the groups may be empty; \f(CW\*(C`::\*(C'\fR is a valid address, equal to \&\f(CW\*(C`0000:0000:0000:0000:0000:0000:0000:0000\*(C'\fR). The hex numbers may be in either case. .PP If the \f(CW\*(C`\-sep\*(C'\fR option is used, its argument is a pattern that matches the separator that separates groups. This defaults to \f(CW\*(C`:\*(C'\fR. The \&\f(CW\*(C`\-style\*(C'\fR option is used to denote which case the hex numbers may be. The default style, \f(CW\*(AqHeX\*(Aq\fR indicates both lower case letters \f(CW\*(Aqa\*(Aq\fR to \f(CW\*(Aqf\*(Aq\fR and upper case letters \f(CW\*(AqA\*(Aq\fR to \f(CW\*(AqF\*(Aq\fR will be matched. The style \f(CW\*(AqHEX\*(Aq\fR restricts matching to upper case letters, and \f(CW\*(Aqhex\*(Aq\fR only matches lower case letters. .PP If \f(CW\*(C`{\-keep}\*(C'\fR is used, \f(CW$1\fR to \f(CW$9\fR will be set. \f(CW$1\fR will be set to the matched address, while \f(CW$2\fR to \f(CW$9\fR will be set to each matched group. If a group is omitted because it contains all zeros, its matching variable will be the empty string. .PP Example: .PP .Vb 5 \& "2001:db8:85a3::8a2e:370:7334" =~ /$RE{net}{IPv6}{\-keep}/; \& print $2; # \*(Aq2001\*(Aq \& print $4; # \*(Aq85a3\*(Aq \& print $6; # Empty string \& print $8; # \*(Aq370\*(Aq .Ve .PP Perl 5.10 (or later) is required for this pattern. .ie n .SS "$RE{net}{domain}" .el .SS "\f(CW$RE{net}{domain}\fP" .IX Subsection "$RE{net}{domain}" Returns a pattern to match domains (and hosts) as defined in \s-1RFC 1035.\s0 Under I{\-keep} only the entire domain name is returned. .PP \&\s-1RFC 1035\s0 says that a single space can be a domainname too. So, the pattern returned by \f(CW$RE{net}{domain}\fR recognizes a single space as well. This is not always what people want. If you want to recognize domainnames, but not a space, you can do one of two things, either use .PP .Vb 1 \& /(?! )$RE{net}{domain}/ .Ve .PP or use the \f(CW\*(C`{\-nospace}\*(C'\fR option (without an argument). .PP \&\s-1RFC 1035\s0 does \fBnot\fR allow host or domain names to start with a digits; however, this restriction is relaxed in \s-1RFC 1101\s0; this \s-1RFC\s0 allows host and domain names to start with a digit, as long as the first part of a domain does not look like an \s-1IP\s0 address. If the \f(CW\*(C`{\-rfc1101}\*(C'\fR option is given (as in \f(CW\*(C`$RE {net} {domain} {\-rfc1101}\*(C'\fR), we will match using the relaxed rules. .SH "REFERENCES" .IX Header "REFERENCES" .IP "\fB\s-1RFC 1035\s0\fR" 4 .IX Item "RFC 1035" Mockapetris, P.: \fI\s-1DOMAIN NAMES\s0 \- \s-1IMPLEMENTATION AND SPECIFICATION\s0\fR. November 1987. .IP "\fB\s-1RFC 1101\s0\fR" 4 .IX Item "RFC 1101" Mockapetris, P.: \fI\s-1DNS\s0 Encoding of Network Names and Other Types\fR. April 1987. .SH "SEE ALSO" .IX Header "SEE ALSO" Regexp::Common for a general description of how to use this interface. .SH "AUTHOR" .IX Header "AUTHOR" Damian Conway \fIdamian@conway.org\fR. .SH "MAINTENANCE" .IX Header "MAINTENANCE" This package is maintained by Abigail (\fIregexp\-common@abigail.be\fR). .SH "BUGS AND IRRITATIONS" .IX Header "BUGS AND IRRITATIONS" Bound to be plenty. .PP For a start, there are many common regexes missing. Send them in to \fIregexp\-common@abigail.be\fR. .SH "LICENSE and COPYRIGHT" .IX Header "LICENSE and COPYRIGHT" This software is Copyright (c) 2001 \- 2017, Damian Conway and Abigail. .PP This module is free software, and maybe used under any of the following licenses: .PP .Vb 4 \& 1) The Perl Artistic License. See the file COPYRIGHT.AL. \& 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2. \& 3) The BSD License. See the file COPYRIGHT.BSD. \& 4) The MIT License. See the file COPYRIGHT.MIT. .Ve