I have a string and I want to extract certain part of the string using regex.
Below is my script. I could able to get the expected output. But need to know do we have any alternative way to achieve this.
#!/usr/bin/perl
use strict; use warnings;
my $str = "Network=ABC,Network=10,Node=N360,Slot=3,Unit=R1,Group=RU,DeviceSet=1,Device=2";
if($str =~ m/(.*),Device/){
print "Out: $1";
} else {
print "Not matching";
}
If the string contains Device=<anydigit> at the end, then it should not print Device=<anydigit> and rest everything it should print. I am doing this using (.*) expression. Apart from this any alternative we have?