title: sed can't match 0 or 1 time
body: <p>I'm writing a bash script on Cent OS7. Now I need to use <code>sed</code> to remove all lines which don't contain <code>.jpg</code> or <code>.jpeg</code>.<br></p>
  
  <p>Here is my script:<br></p>
  
  <pre><code>sed -i -e '/\.jp(e)?g/!d' myfile
  </code></pre>
  
  <p>But it will delete all lines, which means that it doesn't work as expected.<br></p>
  
  <p>However, if I do <code>sed -i -e '/\.jpg/!d' myfile</code> or <code>sed -i -e '/\.jpeg/!d' myfile</code>. Both of them work well.</p>