From: singsang Date: 2006-09-04T21:15:19+09:00 Subject: Compiling Regexp only once Dear all, Writing some httpd logfile pre-processing (splitting it up, getting already some basic numbers), I think that I should compile the Regexp for the logfile entry only once. So my guess is that I should have perhaps a class LogFormat that holds this as a class variable or a class constant. Below I use a non-tested regular expression that is not complete yet. So the idea is to have: class LogFormat @@RegEx = Regexp.new( '(\S+) (\S+) (\S+) \[(\d+)/(\w+)/(\d+) [+\-]\d+?\]' ) def LogFormat.regex @@RegEx end end If now from a class LogLine (instanciated for each line in the logfile) I use something like class LogLine # ... ip, rfc931, user, day, month, year, offset = line.match(LogFormat.regex) # ... end My question: How often is the Regexp compiled? When? When the definition of LogFormat is read first? Btw: If anybody has a ready-to-use regex for the common log format this would be great, but I will get that done as far as I need by myself. ;-) Other question: Does anybody know a "Webalizer" sort of thing written in Ruby? Thank you all so much Herm (using a strange google account, I know)