【发布时间】:2021-05-13 22:58:21
【问题描述】:
执行以下 chef inspec 命令时出现错误。
describe command ("cat sql.conf | grep 'log_filename'") do
its('stdout') {should match (/^'sql-(\d)+.log'/)}
end
预期的模式匹配是sql-20201212.log。请检查。
【问题讨论】:
执行以下 chef inspec 命令时出现错误。
describe command ("cat sql.conf | grep 'log_filename'") do
its('stdout') {should match (/^'sql-(\d)+.log'/)}
end
预期的模式匹配是sql-20201212.log。请检查。
【问题讨论】:
此正则表达式 /^'sql-(\d)+.log'/ 与此字符串 sql-20201212.log 不匹配。你可以试试https://regexr.com/
您的正则表达式存在一些问题:
' 在您的正则表达式中,但不在您的字符串中. 匹配除换行符以外的任何字符,也许您只想匹配一个点(?),如果是这样,那么您需要例如逃脱它\.
\d (())所以,这个正则表达式 ^sql-\d+\.log$ 将匹配 sql-20201212.log 字符串。我还添加了$ 来匹配字符串的结尾。
【讨论】: