0

I have logs in a common landing directory as follows

12345_ABCZ_AA_Loader.20141218.095950941319000.log 12345_ABCZ_AA_Loader.20141218.095950941319000.log.1 12345_ABCZ_AA_Loader.20141218.095950941319000.log.2

12345_ABCZ_AA_BB_Loader.20141218.095950941319000.log

and some plain logs as well

SCheckReport.log

I need a regular expression which satisfies both requirements and grabs all logs for todays date.

Thanks

10
  • 2
    How about "."? It does satisfy all requirements you listed ... Commented Dec 18, 2014 at 14:29
  • Wont work as it picks too many files and not limited to just .log files Commented Dec 18, 2014 at 16:37
  • that won't part of your requirement ... Commented Dec 18, 2014 at 16:44
  • i am looking at log files only as per Original post. Commented Dec 18, 2014 at 17:04
  • exactly. So, there is nothing to filter out :) If your requirement is to only match ".log" files, you should have mentioned it in your question. In that case, the regex you are looking for is \.log Try to be more clear next time. There are not telepaths here. Commented Dec 18, 2014 at 17:24

1 Answer 1

1

While the question isn't exactly clear, this would match those Strings:

^(.*).log(.\d+)?$

EDIT: This doesn't look at todays date, but from your example, one of the filenames doesn't contain a date.

If you want the date, then use:

^(.*)20141218(.*).log(.\d+)?$

I'll leave it to you to build the regex String from current locale date.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the quick response, Just to be clear if i needed files from the sample one to be picked for 20141218 what changes would i need to make to your regex (ignore plain sample 2).
I've edited the post to show the required regex for enforcing presence of the date. Use the 2nd regex statement in the answer. It passes a quick sanity check at RegexPal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.