-3

Is this pattern correct?

logPattern = ^NAME.log(-\d+)?$ 

What is the purpose of this?

0

1 Answer 1

1

Quoting directly from regex101 - a great page for testing and explaining regular expressions:

/^NAME.log(-\d+)?$/ 
  • ^ assert position at start of the string
  • NAME matches the characters NAME literally (case sensitive)
  • . matches any character (except newline)
  • log matches the characters log literally (case sensitive)

Capturing group (-\d+)?

  • Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
  • - matches the character - literally
  • \d match a digit [0-9]
  • Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
  • $ assert position at end of the string

So basically, this searches for strings (particularly file names I suppose) matching the pattern NAME.log or NAME.log-123456789 (no limit on number of digits).

Most probably it should be changed to match literal dot instead of "any character", so a backslash (\) should be added before the dot in the expression.

1
  • @JoséLuis - welcome to StackOverflow. As a general rule, please do not post answers like 'Thank you', but accept the answer instead. You can read more about it here: unix.stackexchange.com/tour Commented Sep 23, 2015 at 13:22

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.