in reply to
Re: Parenthesis grouping into regexes.
in thread Parenthesis grouping into regexes.
Here is an example with data made up to match your regular expressions. Are you sure about the fourth colon in $ip6?
use strict;
use warnings;
my $ip4 = qr !(?: [0-9]{1,3}\.){3} [0-9]{1,3} !x;
my $ip6 = qr !(?: [a-f0-9]{4}:)+ !x;
my $prefix = qr ! / \d \d !x;
my $pattern = qr ! ^($ip4|$ip6) ($prefix)? !x;
while (<DATA>) {
next if $_ !~ $pattern;
print "Hey, I found \$1: $1 \$2: $2\n";
}
__DATA__
no match here
999.888.777.666/66
aaaa:aaaa:aaaa:aaaa:/77