use strict;
my $str = 'usbmuxd/kali-rolling,now 1.1.0-2+b1 amd64 [installed,automatic]
usbutils/kali-rolling,now 1:007-4 amd64 [installed]
util-linux/kali-rolling,now 2.28-6 amd64 [installed]
uuid-runtime/kali-rolling,now 2.28-6 amd64 [installed,automatic]
va-driver-all/kali-rolling,now 1.7.1-2 amd64 [installed,automatic]
vboot-kernel-utils/kali-rolling,now 0~R52-8350.B-1 amd64 [installed,automatic]
vboot-utils/kali-rolling,now 0~R52-8350.B-1 amd64 [installed,automatic]
vdpau-driver-all/kali-rolling,now 1.1.1-3 amd64 [installed,automatic]
';
my $regex = qr/^(.*?)/(.*?),now\s(.*?)\s(.*?)\s/p;
if ( $str =~ /$regex/g ) {
print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n";
# print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n";
# print "Capture Group 2 is $2 ... and so on\n";
}
# ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p'
# Named capture groups can be called via $+{name}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Perl, please visit: http://perldoc.perl.org/perlre.html