use strict;
my $str = 'A0707288dMessage
A0707288dMessage 1
A0707288dMessage 1:Cancel 1
A0707288dMessage-Location. 3
A0707288dMessage-Location. 3:Cancel 3
A0707288dMessage-Location. 3V1
A0707288dMessage-Location. 3:Cancel 3V1
A0707288d[00]Message-Location. 3
A0707288d[00]Message-Location. 3:Cancel 3
A0707288d[00]Message-Location. 3V1
A0707288d[00]Message-Location. 3:Cancel 3V1
RECV,4,0707288,Message
RECV,4,0707288,Message 1
RECV,4,0707288,Message 1:Cancel 1
RECV,4,0707288,Message-Location. 3
RECV,4,0707288,Message-Location. 3:Cancel 3
RECV,4,0707288,Message-Location. 3%0CV1
RECV,4,0707288,Message-Location. 3:Cancel 3%0CV1
RECV,4,0707288,[00]Message-Location. 3
RECV,4,0707288,[00]Message-Location. 3:Cancel 3
RECV,4,0707288,[00]Message-Location. 3%0CV1
RECV,4,0707288,[00]Message-Location. 3:Cancel 3%0CV1';
my $regex = qr/\x19A(\d*)d\[?(\d*)?\]?(.*)-(\S+)\s(\d+)\x0C?(.*)?\x18|\x19A(\d*)d(\S*)\s?(\d*)\:?(.*)\x18|RECV,4,(\d*),\[?(\d*)?\]?(.*)-(\S+)\s(\d+)\%?0?C?(.*)?|RECV,4,(\d*),(\S*)\s?(\d*)\:?(.*)\s/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