re = /(?=.*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]+))/m
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)'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html