title: sed regex not being greedy?
body: <p>In bash I have a string variable <code>tempvar</code>, which is created thus:</p>
  
  <pre><code>tempvar=`grep -n 'Mesh Tally' ${meshtalfile}`
  </code></pre>
  
  <p><code>meshtalfile</code> is a (large) input file which contains some header lines and a number of blocks of data lines, each marked by a beginning line which is searched for in the grep above.</p>
  
  <p>In the case at hand, the variable <code>tempvar</code> contains the following string:</p>
  
  <pre><code>5: Mesh Tally Number 4 977236: Mesh Tally Number 14 1954467: Mesh Tally Number 24 4354479: Mesh Tally Number 34
  </code></pre>
  
  <p>I now wish to extract the line number relating to a particularly mesh tally number - so I define a variable meshnum1 as equal to <code>24</code>, and run the following sed command:</p>
  
  <pre><code>echo ${tempvar} | sed -r "s/^.*([0-9][0-9]*):\sMesh\sTally\sNumber\s${meshnum1}.*$/\1/"
  </code></pre>
  
  <p>This is where things go wrong. I expect the output <code>1954467</code>, but instead I get <code>7</code>. Trying with number <code>34</code> instead returns <code>9</code> instead of <code>4354479</code>. It seems that sed is returning only the last digit of the number - which surely violates the principle of greedy matching? And oddly, when I move the open parenthesis <code>(</code> left a couple of characters to include <code>.*</code>, it returns the whole line up to and including the single character it was previously returning. Surely it cannot be greedy in one situation and antigreedy in another? Hopefully I have just done something stupid with the syntax...</p>