I have this output from router command:
Interface IP-Address OK? Method Status Protocol
POS0/0/0 10.137.99.2 YES NVRAM up up
I want to find a regular expression to identify the IP-Address:
I tried with:
if ( $_ =~ m/(.*?)\s*?(.*?)\s*?(.*?)\s*?(.*)/i ){
#print "$1->$2\n";
$sources{$2}=$1;
}
and then use $2 as ip.
However, it does not work; where am I wrong?
PacoRG’s answer works nicely, but to explain where yours is going wrong:
Remember that
*can match no occurrences. You’re telling each group to match as little as possible, so the first 3 groups are capturing nothing. Further, you want to grab as many consecutive whitespace characters as possible, not as few.Keeping with a RegEx somewhat like your original, you could use