re = /(?P<Timestamp>\b(?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?)\s+\d+\s+\d+:\d+:\d+)\b\s+(?P<FW_ip_addr>\d+\.\d+\.\d+\.\d+)\s+(?P<Event_id>%\w+-\d+-\d+):\s+(?P<Event_message>Teardown ICMP connection for faddr)\s+(?P<foreign_ip_addr>.*)\s+gaddr\s+(?P<global_ip_addr>.*)\s+laddr\s+(?P<local_ip_addr>.*)/
str = 'Jul 25 23:56:11 210.56.128.109 %PIX-6-302021: Teardown ICMP connection for faddr 192.168.20.161/1 gaddr GAIA_172.20.8.11/0 laddr GAIA_172.20.8.11/0
Jul 25 23:56:33 210.56.128.109 %PIX-6-302021: Teardown ICMP connection for faddr Thetis2/41817 gaddr 210.56.128.109/0 laddr 210.56.128.109/0
'
# 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