re = /(?P<request_date>^[\w\/\:]+)\s+(?P<request_offset>[\d\+]+)\s+\[(?P<request_id>.+)\]\s+(?P<request_inout>[\-\>\<]+)\s+((?P<request_method>[GET|POST|HEAD|PUT|DELETE|CONNECT|OPTIONS|TRACE|PATCH]+)?\s+(?P<request_path>[^;][^;][a-zA-Z0-9\/\_\-\.\=\@\:\%\+\~\#\?\&\{\}\[\]\|]+)\s+(?P<request_protocol>.+)\s+|(?P<request_code>\d+)\s+(?P<request_filetype>.+)\s+(?P<request_duration>[\d\w]+)\s+)/m
str = '14/May/2021:09:37:39 +0000 [715153] -> GET /content/ams/healthcheck/regent.html HTTP/1.1
14/May/2021:09:37:39 +0000 [2585977] <- 200 text/html;charset=UTF-8 6ms
14/May/2021:10:37:39 +0100 [1502141] -> GET /libs/granite/csrf/token.json HTTP/1.1
14/May/2021:09:37:39 +0000 [715152] <- 200 text/html;charset=UTF-8 6ms
14/May/2021:11:52:22 +0000 [11097977] -> GET /content/onehub_nfz/ru/ru/model-overview/caddy.html?tc=oa-[B]_[Caddy]_[All]_[None]_[BMM]_[RU]_[Eval]_Yandex_Search_AON_Paid_Search-Yandex-cpc-Search-banner&kw={PHRASE}&utm_source=yandex&utm_medium=cpc&utm_campaign=[B]_[Caddy]_[All]_[None]_[BMM]_[RU]_[Eval]_Yandex_Search_AON_Paid_Search&utm_term={PHRASE}&utm_content=s_{SRC}|cid_45783621|gid_{GBID}|aid_8728578416|pid_{PHRASE_EXPORT_ID}|rid_{PARAM126}|p_{POS}|pty_{PTYPE} HTTP/1.1
'
# 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