user2246680
user2246680

Reputation: 41

Matching date ranges using Regex

I need a regex to match some file names, actually they are dated logs, and I only need to fetch logs from say 24th to 31st. Also there are 2 type of logs.

Log filenames are as follows:

log_file_first-Type_24-03-2013
log_file_second-Type_24-03-2013

I have tried following:

log_file_(first|second)\-Type_(2,3)(4,1)\-03\-2013

But this takes in 21st also, how to do this?

Upvotes: 2

Views: 591

Answers (3)

Amar
Amar

Reputation: 12020

Try this:

log_file_(first|second)\-Type_(2[4-9]|3[01])\-03\-2013

Upvotes: 1

Grzegorz Olszewski
Grzegorz Olszewski

Reputation: 1428

Regular expressions are powerful, but also have several limitations. There are not so good in integers' ranges. This is not an elegant solution, but works:

log_file_(first|second)\-Type_(2[4-9]|30|31)\-03\-2013

Upvotes: 3

Loamhoof
Loamhoof

Reputation: 8293

log_file_(first|second)-Type_(2[4-9]|3[01])-03-2013

Upvotes: 0

Related Questions