Saturday 21 September 2019

Sed lazy regex is not lazy

As a follow up to a previous question about lazy matching using grep, I have a similar question about sed:



Suppose I have the following text file (called 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}}


If I run:



$ sed -r 's/\\includegraphics.*?}//g' test.txt
\centerline{
\centerline{
\centerline{



Then it matches all the way to the last curly bracket. Should it not match just to the first?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...