【发布时间】:2014-04-22 16:49:01
【问题描述】:
我遇到了 bash 正则表达式匹配的问题。我有这样的正则表达式:
re="fatal: file not found: .+/tmp_dir_1234/([^\ ]*) \(No such file or directory\)"
test="fatal: file not found: /some/path/irrelevant/something/tmp_dir_1234/somefile.txt (No such file or directory)"
if [[ "$test" =~ "$re" ]]; then
echo "match!"
fi
对我来说,这里的一切现在看起来都不错,但由于某种原因,在调试 bash 脚本时我可以看到它与这里的字符串不匹配:
+ [[ fatal: file not found: /some/path/irrelevant/something/tmp_dir_1234/somefile.txt (No such file or directory) =~ fatal: file not found: \.\+/tmp_dir_1234/\(\[\^\\ ]\*\) \\\(No such file or directory\\\) ]]
由于某种原因正则表达式模式被转义。
【问题讨论】: