Skip to main content
added 12 characters in body
Source Link
Paweł Rumian
  • 1.7k
  • 10
  • 23

Quoting directly from regex101regex101 - 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.

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.

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.

Source Link
Paweł Rumian
  • 1.7k
  • 10
  • 23

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.