Home > OS >  Regex for log file name
Regex for log file name

Time:05-05

I'm using filebeat to watch log files, how can I construct a regular expression for files with the following extensions: .log, .log.1, .log.2. It also should ignore all other extensions such as .json or .gz. Thanks.

CodePudding user response:

You could go with something like this (the parenthesis are used for grouping):

(. )(\.log)(\.\d )?

I always use this site to try out and work on regular expressions. You can insert the matching texts and visually see what matches. Hope this helps.

CodePudding user response:

Try this (.)*(\.log|\log1|\log2){1} There's a great online regex tool to help you doodle with various regexes at rubular.com

  • Related