rubyinspec

chef inspec output consists of error due to regex


When executing the below chef inspec command getting error.

describe command ("cat sql.conf | grep 'log_filename'") do
  its('stdout') {should match (/^'sql-(\d)+.log'/)}
end

Expected pattern matching is sql-20201212.log. pls check.


Solution

  • This regex /^'sql-(\d)+.log'/ doesn't match this string sql-20201212.log. You can try it out on https://regexr.com/

    There are a few problems with your regex:

    So, this regex ^sql-\d+\.log$ would match sql-20201212.log string. I also added $ to match the end of the string.