title: Regex for wrapping digits with curly braces?
body: <p>I am trying to using Python's <code>re.sub()</code> to match a string with an <code>e</code> character and insert curly braces immediately after the <code>e</code> character and after the lastdigit. For example:</p>
  
  <pre><code>12.34e56 to 12.34e{56}
  1e10 to 1e{10}
  </code></pre>
  
  <p>I can't seem to find the correct regex to insert the desired curly braces. For example, I can properly insert the left brace like this:</p>
  
  <pre><code>&gt;&gt;&gt; import re
  &gt;&gt;&gt; x = '12.34e10'
  &gt;&gt;&gt; pattern = re.compile(r'(e)')
  &gt;&gt;&gt; sub = z = re.sub(pattern, "\1e{", x)
  &gt;&gt;&gt; print(sub)
      12.34e{10 # this is the correct placement for the left brace
  </code></pre>
  
  <p>My problem arises when using two back references.</p>
  
  <pre><code>&gt;&gt;&gt; import re
  &gt;&gt;&gt; x = '12.34e10'
  &gt;&gt;&gt; pattern = re.compile(r'(e).+($)')
  &gt;&gt;&gt; sub = z = re.sub(pattern, "\1e{\2}", x)
  &gt;&gt;&gt; print(sub)
      12.34e{} # this is not what I want, digits 10 have been removed
  </code></pre>
  
  <p>Can anyone point out my problem? Thanks for the help.</p>