# Regex quick ? solved, actually, move along

**URL:** <https://www.ruby-forum.com/t/regex-quick-solved-actually-move-along/112280>\
**Category:** Ruby\
**Created:** [August 17, 2007, 1:16am UTC](https://www.ruby-forum.com/t/regex-quick-solved-actually-move-along/112280 "2007-08-17T01:16:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [August 17, 2007, 1:16am UTC](https://www.ruby-forum.com/t/regex-quick-solved-actually-move-along/112280/1 "2007-08-17T01:16:32Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [August 17, 2007, 1:42am UTC](https://www.ruby-forum.com/t/regex-quick-solved-actually-move-along/112280/2 "2007-08-17T01:42:36Z")

</div>

Hi –

On Fri, 17 Aug 2007, Simon S. wrote:

> 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

---

<div class="post-metadata">

**Author:** ![simonsaid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b5e925/32.png) [@simonsaid](https://www.ruby-forum.com/u/simonsaid)\
**Post date:** [August 17, 2007, 1:10pm UTC](https://www.ruby-forum.com/t/regex-quick-solved-actually-move-along/112280/3 "2007-08-17T13:10:37Z")

</div>

2007/8/17, Simon S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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.

That bit looks like a time zone offset with the name (“PDT” which is  
“Pacific Daylight Savings Time” IIRC).

> [“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. 🙂

If you want to be really sure you parse the name that you expect you can  
do

irb(main):001:0\> afile = “2007-08-10.152314-0700PDT.txt”  
=\> “2007-08-10.152314-0700PDT.txt”  
irb(main):002:0\> afile[/^\d{4}-\d{2}-\d{2}.(\d{6})-\d{4}[A-Z]+.txt$/,  
1]  
=\> “152314”

Kind regards

robert
