how to find .log.1, log.2, ....?

Viewed 28

i have this regex in .sh file to lookup for .log files and gz files:

 regex="(\.log|\.gz)"

now i realized that a lot of files are ending with .log.1, .log.2, .log.3

as i'm a noob regarding this, can someone tell me please how to change my regex to find these files too? Thank you ^^

1 Answers

Played on https://rubular.com/ for a minute.

\.log\.?[0-9]*|\.gz

\.log\ search for .log, \.? searches for zero or one . and [0-9]* for some possible numbers.

Slightly more complicated :

\.log(\.?[0-9]+)?|\.gz avoids some pitfalls as described by tripleee's comment.

Related