Regexp::Common::net (3)
Leading comments
Automatically generated by Pod::Man 4.07 (Pod::Simple 3.32) Standard preamble: ========================================================================
NAME
Regexp::Common::net -- provide regexes for IPv4 addresses.SYNOPSIS
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 => ':'}/ 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"; }
DESCRIPTION
Please consult the manual of Regexp::Common for a general description of the works of this interface.Do not use this module directly, but load it via Regexp::Common.
This modules gives you regular expressions for various style IPv4 and
$RE{net}{IPv4}
Returns a pattern that matches a validFor this pattern and the next four, under "-keep" (See Regexp::Common):
- $1
- captures the entire match
- $2
- captures the first component of the address
- $3
- captures the second component of the address
- $4
- captures the third component of the address
- $5
- captures the final component of the address
$RE{net}{IPv4}{dec}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/[.]/".
$RE{net}{IPv4}{hex}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/[.]/". "-sep=""" and "-sep=" "" are useful alternatives.
$RE{net}{IPv4}{oct}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/[.]/".
$RE{net}{IPv4}{bin}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/[.]/".
$RE{net}{MAC}
Returns a pattern that matches a validFor this pattern, and the next four, under "-keep" (See Regexp::Common):
- $1
- captures the entire match
- $2
- captures the first component of the address
- $3
- captures the second component of the address
- $4
- captures the third component of the address
- $5
- captures the fourth component of the address
- $6
- captures the fifth component of the address
- $7
- captures the sixth and final component of the address
This pattern, and the next four, have a "subs" method as well, which will transform a matching
The "subs" method will not work for binary
$RE{net}{MAC}{dec}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/:/".
$RE{net}{MAC}{hex}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/:/".
$RE{net}{MAC}{oct}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/:/".
$RE{net}{MAC}{bin}{-sep}
Returns a pattern that matches a validIf "-sep=P" is specified the pattern P is used as the separator. By default P is "qr/:/".
$RE{net}{IPv6}{-sep => ':'}{-style => 'HeX'}
Returns a pattern matching IPv6 numbers. An IPv6 address consists of eigth 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; "::" is a valid address, equal to "0000:0000:0000:0000:0000:0000:0000:0000"). The hex numbers may be in either case.If the "-sep" option is used, its argument is a pattern that matches the separator that separates groups. This defaults to ":". The "-style" option is used to denote which case the hex numbers may be. The default style, 'HeX' indicates both lower case letters 'a' to 'f' and upper case letters 'A' to 'F' will be matched. The style 'HEX' restricts matching to upper case letters, and 'hex' only matches lower case letters.
If "{-keep}" is used, $1 to $9 will be set. $1 will be set to the matched address, while $2 to $9 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.
Example:
"2001:db8:85a3::8a2e:370:7334" =~ /$RE{net}{IPv6}{-keep}/; print $2; # '2001' print $4; # '85a3' print $6; # Empty string print $8; # '370'
Perl 5.10 (or later) is required for this pattern.
$RE{net}{domain}
Returns a pattern to match domains (and hosts) as defined in
/(?! )$RE{net}{domain}/
or use the "{-nospace}" option (without an argument).
REFERENCES
- RFC 1035
-
Mockapetris, P.: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION. November 1987.
- RFC 1101
-
Mockapetris, P.: DNSEncoding of Network Names and Other Types. April 1987.
SEE ALSO
Regexp::Common for a general description of how to use this interface.AUTHOR
Damian Conway damian@conway.org.MAINTAINANCE
This package is maintained by Abigail (regexp-common@abigail.be).BUGS AND IRRITATIONS
Bound to be plenty.For a start, there are many common regexes missing. Send them in to regexp-common@abigail.be.
LICENSE and COPYRIGHT
This software is Copyright (c) 2001 - 2013, Damian Conway and Abigail.This module is free software, and maybe used under any of the following licenses:
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 Licence. See the file COPYRIGHT.BSD. 4) The MIT Licence. See the file COPYRIGHT.MIT.