Codex

Regexp::Common::net

Section: User Contributed Perl Documentation (3pm)

Updated: 2013-03-13

Index?action=index Return to Main Contents


NAME

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

SYNOPSIS

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 MAC (or ethernet) addresses.

$RE{net}{IPv4}

Returns a pattern that matches a valid IP address in ``dotted decimal''. Note that while is not a valid IP address, it does match , but this is because contains a valid IP address, namely . To prevent the unwanted matching, one needs to anchor the regexp: .
For this pattern and the next four, under (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 valid IP address in ``dotted decimal''

If P is specified the pattern P is used as the separator. By default P is .

$RE{net}{IPv4}{hex}{-sep}

Returns a pattern that matches a valid IP address in ``dotted hexadecimal'', with the letters to capitalized.
If P is specified the pattern P is used as the separator. By default P is . and are useful alternatives.

$RE{net}{IPv4}{oct}{-sep}

Returns a pattern that matches a valid IP address in ``dotted octal''

If P is specified the pattern P is used as the separator. By default P is .

$RE{net}{IPv4}{bin}{-sep}

Returns a pattern that matches a valid IP address in ``dotted binary''

If P is specified the pattern P is used as the separator. By default P is .

$RE{net}{MAC}

Returns a pattern that matches a valid MAC or ethernet address as colon separated hexadecimals.

For this pattern, and the next four, under (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 method as well, which will transform a matching MAC 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.
The method will not work for binary MAC addresses if the Perl version predates 5.6.0.

$RE{net}{MAC}{dec}{-sep}

Returns a pattern that matches a valid MAC address as colon separated decimals.

If P is specified the pattern P is used as the separator. By default P is .

$RE{net}{MAC}{hex}{-sep}

Returns a pattern that matches a valid MAC address as colon separated hexadecimals, with the letters to in lower case.
If P is specified the pattern P is used as the separator. By default P is .

$RE{net}{MAC}{oct}{-sep}

Returns a pattern that matches a valid MAC address as colon separated octals.

If P is specified the pattern P is used as the separator. By default P is .

$RE{net}{MAC}{bin}{-sep}

Returns a pattern that matches a valid MAC address as colon separated binary numbers.

If P is specified the pattern P is used as the separator. By default P is .

$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 ). The hex numbers may be in either case.
If the option is used, its argument is a pattern that matches the separator that separates groups. This defaults to . The option is used to denote which case the hex numbers may be. The default style, indicates both lower case letters to and upper case letters to will be matched. The style restricts matching to upper case letters, and only matches lower case letters.
If is used, to will be set. will be set to the matched address, while to 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:

Perl 5.10 (or later) is required for this pattern.

$RE{net}{domain}

Returns a pattern to match domains (and hosts) as defined in RFC 1035. Under I{-keep} only the entire domain name is returned.

RFC 1035 says that a single space can be a domainname too. So, the pattern returned by 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
or use the option (without an argument).
RFC 1035 does not allow host or domain names to start with a digits; however, this restriction is relaxed in RFC 1101; this RFC allows host and domain names to start with a digit, as long as the first part of a domain does not look like an IP address. If the option is given (as in ), we will match using the relaxed rules.

REFERENCES

RFC 1035
Mockapetris, P.: DOMAIN NAMES - IMPLEMENTATION AND SPECIFICATION. November 1987.:
RFC 1101
Mockapetris, P.: DNS Encoding 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 [email protected].

MAINTAINANCE

This package is maintained by Abigail ([email protected]).

BUGS AND IRRITATIONS

Bound to be plenty.

For a start, there are many common regexes missing. Send them in to [email protected].

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:


Index

NAME

SYNOPSIS

DESCRIPTION

$RE{net}{IPv4}

$RE{net}{IPv4}{dec}{-sep}

$RE{net}{IPv4}{hex}{-sep}

$RE{net}{IPv4}{oct}{-sep}

$RE{net}{IPv4}{bin}{-sep}

$RE{net}{MAC}

$RE{net}{MAC}{dec}{-sep}

$RE{net}{MAC}{hex}{-sep}

$RE{net}{MAC}{oct}{-sep}

$RE{net}{MAC}{bin}{-sep}

$RE{net}{IPv6}{-sep = ':'}{-style => 'HeX'}>

$RE{net}{domain}

REFERENCES

SEE ALSO

AUTHOR

MAINTAINANCE

BUGS AND IRRITATIONS

LICENSE and COPYRIGHT