use strict;
my $str = '0-1:F.F.0*255(000000000000000)
0-1:F.F.2*255(000000000111100)
0-1:0.0.0*255(1ZPA0020280814)
1-0:C.1.0*255(0020280814)
1-0:0.0.2*255(4U110017012)
1-0:0.0.3*255(00000000)
1-0:0.9.1*255(22:38:32)
1-0:0.9.2*255(23-12-28)
1-0:0.2.0*255(05 r01)
1-0:0.1.2*01(231201000000)
1-0:0.1.2*02(231101000000)
1-0:0.1.2*03(231001000000)
1-0:0.1.2&04(230927075308)
1-0:1.8.0*255(000003.6382*kWh)
1-0:1.8.0*254(000003.6382*kWh)
1-0:1.8.0*01(000003.6382*kWh)
1-0:1.8.0*02(000003.6382*kWh)
1-0:1.8.0*03(000003.6382*kWh)
1-0:1.8.0&04(000000.0000*kWh)
1-0:1.8.1*255(000003.6382*kWh)
1-0:1.8.1*254(000003.6382*kWh)
1-0:1.8.1*01(000003.6382*kWh)
1-0:1.8.1*02(000003.6382*kWh)
1-0:1.8.1*03(000003.6382*kWh)
1-0:1.8.1&04(000000.0000*kWh)
1-0:1.8.2*255(000000.0000*kWh)
1-0:1.8.2*254(000000.0000*kWh)
1-0:1.8.2*01(000000.0000*kWh)
1-0:1.8.2*02(000000.0000*kWh)
1-0:1.8.2*03(000000.0000*kWh)
1-0:1.8.2&04(000000.0000*kWh)
1-0:2.8.0*255(000000.6248*kWh)
1-0:2.8.0*254(000000.6248*kWh)
1-0:2.8.0*01(000000.6248*kWh)
1-0:2.8.0*02(000000.6248*kWh)
1-0:2.8.0*03(000000.6248*kWh)
1-0:2.8.0&04(000000.0000*kWh)
1-0:2.8.1*255(000000.6248*kWh)
1-0:2.8.1*254(000000.6248*kWh)
1-0:2.8.1*01(000000.6248*kWh)
1-0:2.8.1*02(000000.6248*kWh)
1-0:2.8.1*03(000000.6248*kWh)
1-0:2.8.1&04(000000.0000*kWh)
1-0:2.8.2*255(000000.0000*kWh)
1-0:2.8.2*254(000000.0000*kWh)
1-0:2.8.2*01(000000.0000*kWh)
1-0:2.8.2*02(000000.0000*kWh)
1-0:2.8.2*03(000000.0000*kWh)
1-0:2.8.2&04(000000.0000*kWh)
1-0:0.2.2*255(00750101)
1-0:C.15.0*255(23-04-07)
1-0:0.2.6*255(intErn)
1-0:C.6.0*255(00 00:07:33)
1-0:C.14.0*255(T2)
1-0:C.9.0*255(+27.0*C)
1-0:C.6.3*255(3.66*V)
1-0:C.1.6*255(98FC51FF)';
my $regex = qr/^((?P<a>[0-9]{1,3})-)?((?P<b>[0-9]{1,3}):)?(?P<cde>(?P<c>[0-9A-F]{1,3}).(?P<d>[0-9A-F]{1,3})(.(?P<e>[0-9A-F]{1,3}))?)([\*\&](?P<f>[0-9A-F]{1,3}))?\((?P<value>[^*^\)]*)(([\*])(?P<unit>\w*))?\)$/mp;
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