sed can't match 0 or 1 time

Viewed 8806

I'm writing a bash script on Cent OS7. Now I need to use sed to remove all lines which don't contain .jpg or .jpeg.

Here is my script:

sed -i -e '/\.jp(e)?g/!d' myfile

But it will delete all lines, which means that it doesn't work as expected.

However, if I do sed -i -e '/\.jpg/!d' myfile or sed -i -e '/\.jpeg/!d' myfile. Both of them work well.

3 Answers
Related