title: Using ? with sed
body: <p>I just want to get the number of a file that may or may not be gzip'd.  However, it appears that a regular expression in sed does not support a <code>?</code>.  Here's what I tried:</p>
  
  <p><code>echo 'file_1.gz'|sed -n 's/.*_\(.*\)\(\.gz\)?/\1/p'</code></p>
  
  <p>and nothing was returned.  Then I added a <code>?</code> to the string being analyzed:</p>
  
  <p><code>echo 'file_1.gz?'|sed -n 's/.*_\(.*\)\(\.gz\)?/\1/p'</code></p>
  
  <p>and got:</p>
  
  <p><code>1</code></p>
  
  <p>So, it looks like the <code>?</code> used in most regex's is not supported in sed, right?  Well then, I would just like sed to give a <code>1</code> for <code>file_1</code> and <code>file_1.gz</code>.  What's the best way to do that in a bash script if execution time is critical?</p>