Saturday, September 21, 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

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...