re = /(?<date>\d+\-\d+\-\d+).(?<time>\d+:\d+:\d+).(?<timetaken>\d+).(?<cip>\d+\.\d+\.\d+\.\d+).(?<scstatus>\d+).(?<scaction>\S+).(?<scbytes>\d+).(?<csbytes>\d+).(?<csmethod>\S+).(?<csurischeme>\S+).(?<cshost>\S+).(?<csuriport>\d+).(?<csuripath>\S+).(?<csuriquery>\S+).(?<csusername>\S+).(?<csauthgroup>\S+).(?<shierarchy>\S+).(?<ssuppliername>\S+).(?<rscontenttype>\S+).(?<csreferer>\S+)."?(?<cs_user_agent>.+)"?./m
str = '2014-03-27 12:39:32 20 10.71.15.207 304 TCP_HIT 367 1470 GET http www.computerworld.com 80 /elqNow/elqFCS.js - - - - 23.196.74.53 application/x-javascript http://www.computerworld.com/s/article/9247206/Gameover_malware_takes_aim_at_Monster.com_and_CareerBuilder.com "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)" OBSERVED "Technology/Internet" - 163.252.254.201 23.44.202.53 52809
'
# 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