vendredi 5 décembre 2014

Perl regex not giving match


Vote count:

0




I am newbie in Perl. I have used regex in Python. I have array list where each elem is text.


" Some explanation about some thing Root ID Priority 12313 Address mac-address Cost 4 Port 1234 This is the awesome root "


Here Cost and Port may be or may not be present in text. So I have written two regex expressions.



foreach $item (@list){
$item =~ /Cost\s+(?<cost>\d+).*?Port\s+(?<port>\d+)/sg;
print "cost: $+{cost} port: $+{port}\n";
$item =~ /Root\s+ID\s+Priority\s+(?<rootPriority>\d+).*?Address\s+(?<rootAddress>\S+).*/sg;
print "rootPriority: $+{rootPriority} rootAddress: $+{rootAddress} \n";

print $item;
}


Output,



cost: 2 port: 4096
rootPriority: rootAddress:
Some explanation about some thing
Root ID Priority 12313
Address mac-address
Cost 2
Port 4096
This is the awesome root


I am not able to understand why I can get values of cost and port but not of rootPriority and rootAddress. And how to get values of rootPriority and rootAddress?



asked 24 secs ago

Netro

727






Perl regex not giving match

Aucun commentaire:

Enregistrer un commentaire