Character class ranges only go up to the first number. So your character classes are asking for (AFAICT) 0-2 or 5 (the second 5 is ignored). Also, the regex is set to start matching at the beginning of the string, but the IP occurs in the middle. Lastly, the dot isn't doing what you think it's doing; it matches any character, not just a dot.
As long as your system guarentees that the lsattr command returns the address in dotted-quad form, this should work:
my $dotted_quad = do { my $allowed_numbers = join '|', 0 .. 255; my $quad = qr/(?: $allowed_numbers )/x qr/ $quad \. $quad \. $quad \. $quad /x; }; . . . if( $ipadd =~ /($dotted_quad)/ ) { $ipaddress = $1; }
"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.
In reply to Re: regexp for extracting IP address
by hardburn
in thread regexp for extracting IP address
by gcazianfnf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |