tags:

views:

8

answers:

1

i'm setting up a directory structure based on dates: 2010/02/01

right now, my rewrite rules look something like this:

([0-9]{4})/([0-9]{2})/([0-9]{2})

I tried limiting the ranges - the month, for instance: ([01-12]{2}) - but that doesn't seem to work. is there a way to do this, or am i making this too complicated and i shouldn't worry about it?

i don't want something like: (01|02|03...10|11|12)

thanks!

A: 

Regular expressions don't see numbers as numbers. It sees each individual digit as a character. So, [01-12] would actually equivocate to [012] or [0-2]. (Someone correct me if I'm wrong on that.)

I'm not a master at RexEx, so someone might have a better solution, but here's what I'd use:

(2\d{3})/(1[0-2]|0[1-9])/(3[0-1]|[1-2]\d|0[1-9])

Untested, but that should restrict your year to the 2000s, your months to 01-12, and your days to 01-31.

Jeff Rupert
Looks like you're correct: http://www.regular-expressions.info/numericranges.html
cmptrgeekken
Awesome, thanks for the checkup on that. =D
Jeff Rupert
that works great! however - the \d wasn't working, so i changed them to [0-9]
neil
Ok, that works too. Depending on the implementation `\w`, `\d`, and `\s` aren't interpreted as character classes. Glad I could help!
Jeff Rupert