From: Johan Dahl Date: 2001-05-30T06:45:21+09:00 Subject: [ruby-talk:15962] Re: .scan() using '/' as the regular expression delimiter >err, my current code looks something like this (noting that it does not in >fact work) > >regExpr1 = /\d+'/'\s+'/'\d+/ >@day, @month, @year = date.scan(regExpr1) > >-Luke > > >"Luke Crook" wrote in message >news:9f12ej$1a5@dispatch.concentric.net... >> I am trying to parse an Apache log file. The date field looks like: >> [22/May/2001:23:54:41 -0700] >> >> How would I use the .scan() method when '/' is the delimiter (I'm trying >to >> store day, month, year as seperate fields). >> I have tried \/, "/" , '/', and even [/] but these do not work. >> >> -Luke Crook >> >> Hi You are using the wrong function. scan should match the whole pattern for each item in the produced array so for example "1/2/3".scan(/\d+/) ==> ["1", "2", "3"]. Use the regular expression matching operator =~ (equals tilde) instead. Like this date = "[22/May/2001:23:54:41 -0700]" date =~ /(\d+)\/(\S+)\/(\d+)/ @day, @month, @year = $1, $2, $3 Notice \S matches any non-whitespace character. \s matches whitespace -- Johan Dahl, Research Engineer Department of Linguistics and Phonetics, Lund University Address: Helgonabacken 12, 223 62 Lund, SWEDEN Tel: +46-(0)46-2228443 Fax: +46-(0)46-2224210 E-mail: mailto:Johan.Dahl@ling.lu.se WWW: http://www.ling.lu.se/persons/Johan/