LoginSignup
3
5

More than 5 years have passed since last update.

Apacheログをrubyで扱うときの正規表現

Posted at

fluentdそのままですがいつも忘れるのでメモ。

format = /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*) [^ ]* "(?<agent>[^\"]*)"$/
m = format.match(line)
puts m[:host] # 192.168.0.1
puts m[:time] # 10/Jul/2013:13:53:15 +0900
3
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
5