Hi --

On Fri, 17 Aug 2007, Simon Schuster wrote:

> afile = "2007-08-10.152314-0700PDT.txt"
>
> some notes about it, is that the first part before the . is date, and
> subject to change, the second I thought was an arbitrary id for logs
> of the same day, but it's a timestamp, and the "-0700PDT.txt" is
> always the same per log per day and can be cut out as such. The date,
> as well, can be discarded. I'm just looking to isolate, and then
> parse, the "152314" in this case.
>
> this is as far as I've gotten:
> 089:0> afile.split(/^\d+-\d+-\d+./)
> ["", "152314-0700PDT.txt"]
>
> nevermind I just figured out I could do:
> afile.scan(/\d\d\d\d\d\d/)
> ["152314"]
>
> having taken the time to formulate the question though I'm just going
> to send it because you people are so nice I want to give any little
> bit I've got. :)

Thanks. I'll reciprocate with a small shortcut:

   afile.scan(/\d{6}/)   # 6 digits

Also, you can hand a regex directly to a string:

   afile[/\d{6}/]

which will give you the substring directly (not in an array).


David

-- 
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242)
   RUBY FOR RAILS (http://www.manning.com/black)
* Ruby/Rails training
     & consulting:  Ruby Power and Light, LLC (http://www.rubypal.com)