use strict;
my $str = '19:59:16:394 [Combat] player1 took 4301 damage from Stafrusher(47)
19:59:16:547 [Combat] Stafrage(45) took 12049 damage from player2
19:59:17:060 [Combat] Stafrage(45) took 8621 damage from player3 (Critical)
19:59:17:375 [Combat] Stafrage(45) took 7931 damage from player2 (Critical)';
my $regex = qr/(?=.*Critical)(?P<hour>\d{2}):(?P<min>\d{2}):(?P<sec>\d{2}):(?P<milsec>\d{3}) (\[Loot] Gained (?P<xp>\S+) XP?|\[Loot] Item Acquired: (?P<loot>.*)|\[Loot] Gained (?P<dram>\S+) Dram?|\[Loot] Earned (?P<reputation>\S+) Reputation?|\[Combat] (?P<dude_hurt>.+) took (?P<damages>\S+) damage from (?P<damage_dealer>[\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