假设我有以下文本文件(名为test.txt
):
\centerline{\includegraphics[width=0.50 \columnwidth]{example_graph.pdf}}
\centerline{\includegraphics[width=0.5 \columnwidth]{coarse_grain_illustration.png}}
\centerline{\includegraphics[width= 0.8 \columnwidth]{1y26_energy_dists.pdf}}
如果我使用贪婪的匹配进行搜索,我会得到我期望的结果:
[user@host test]$ grep '\\includegraphics.*df' test.txt
\centerline{\includegraphics[width=0.50 \columnwidth]{example_graph.pdf}}
\centerline{\includegraphics[width= 0.8 \columnwidth]{1y26_energy_dists.pdf}}
===========================================================================================================
但是,如果我使用延迟评估,则无法获得结果:
[user@host test]$ grep '\\includegraphics.*?df' test.txt
===========================================================================================================
是什么给出的?为什么使用惰性评估与基本相同的模式不匹配?
答案 0 :(得分:2)
.*?
或延迟模式。您必须在perl模式下使用grep -P
或grep才能实现它。