2

I am trying to get all logfiles between two dates with regular expressions.

My current expression is ^logfile-?('20120101').

From is "20120101" and end is "20120131"for example.

finding a specific logfile is no problem, i have problems to define the between-days-condition.

splash
  • 13,037
  • 1
  • 44
  • 67
baris
  • 88
  • 1
  • 4
  • 2
    Regular expressions probably are not the tool you want for this, but provide some sample input and desired output so we can help. – alan Apr 02 '12 at 13:20
  • Getting them from the shell? Which one? Or in what language else? – user unknown Apr 02 '12 at 13:46
  • it is ruby. i found the upto-method which is usable for a date either. but still i am interested in the regex which does the same :) – baris Apr 02 '12 at 14:02

2 Answers2

0

You can use this:

import datetime
PSD = datetime.datetime(2019, 7, 1)
PED = datetime.datetime(2019, 7, 31)
dateDelta = (PED-PSD).days
STR = '{'
for date in range(dateDelta+1):
  focusedDate = PSD + datetime.timedelta(date)
  STR += focusedDate.strftime("%Y/%m/%d") + ','
STR = STR[:-1] + "}"
print(STR)

and the result will look like this:

{2019/07/01,2019/07/02,2019/07/03,2019/07/04,2019/07/05,2019/07/06,2019/07/07,2019/07/08,2019/07/09,2019/07/10,2019/07/11,2019/07/12,2019/07/13,2019/07/14,2019/07/15,2019/07/16,2019/07/17,2019/07/18,2019/07/19,2019/07/20,2019/07/21,2019/07/22,2019/07/23,2019/07/24,2019/07/25,2019/07/26,2019/07/27,2019/07/28,2019/07/29,2019/07/30,2019/07/31}
ARCrow
  • 1,360
  • 1
  • 10
  • 26
-1

For the date part of the regex it should be sufficient to search for 201201\d\d. This will match every String from "20120100" to "20120199", so it would match every day in January.

So probably something like this would do it: ^logfile-(201201\d\d)

If you want to reduce it to a specific period in the same month (for example from 7th july till 21th july) then it could look like this:

201207(0[7-9]|1[0-9]|2[0-1])
splash
  • 13,037
  • 1
  • 44
  • 67
  • This will only work for accurate date boundaries, not for `from is "20120405" and end is "20120503" for example`. – user unknown Apr 02 '12 at 13:44
  • i understand, but i would like to reduce the days, so i can say: get all logfiles from 7th july till 21th july. 'start' and 'end' are in the same month. – baris Apr 02 '12 at 14:01