Regular expression filter my logs on date basis

8/23/2019

I have a log file with dates in the format of 23 Aug 2019 05:26:53, I want to filter on date wise, I have written pattern in my yaml file as :

"pattern" : "\\(0?[1-9]|[12][0-9]|3[01]) [A-Z][a-z]{2} d{4}"

Can you please suggest me

-- Lakshmi Reddy
kubernetes
regex
yaml

1 Answer

8/23/2019

Here is a correction to your current regex pattern:

(0?[1-9]|[12][0-9]|3[01]) [A-Z][a-z]{2} \d{4}

The days, month name, and year components are separate by space, not dash. However, I might just use the following simplified (though more targeted) pattern:

\d{1,2} [A-Z][a-z]{2} \d{4} \d{2}:\d{2}:\d{2}

It is highly likely that the above pattern would only target the timestamps in your log file, and it is easier to read than your version.

Demo

-- Tim Biegeleisen
Source: StackOverflow