title: Regex match any setence containing ^ except those that start with \
body: <p>I want to add a delimiter -- <code>$</code> -- to each sentence that contains an exponential -- <code>^</code> -- operator in my text, but I don't want to add this same delimiter when the base of my exponential contains a backslash in it. I tried to use the <code>((?!\\\w+)\w+)\^(\w+)</code> regex to no success.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>input</th>
  <th>what I want</th>
  <th>what I got</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>foo^2</td>
  <td>$foo^2$</td>
  <td>$foo^2$</td>
  </tr>
  <tr>
  <td>\foo^2</td>
  <td>\foo^2</td>
  <td>$foo^2$</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>My code:</p>
  <pre class="lang-py prettyprint-override"><code>from re import sub
  
  sentence = &quot;&quot;&quot;foo^2 
   \bar, \bar^3 
  bar 
  \foo 
   \bar
   foo^5 
  &quot;&quot;&quot;
  
  sub(r'((?!\\\w+)\w+)\^(\w+)', '$\\1^\\2$', sentence)
  </code></pre>
  <p>Gives the following output:</p>
  <pre class="lang-py prettyprint-override"><code>'$foo^2$ \n \x08ar, \x08$ar^3$ \nbar \n\x0coo \n \x08ar\n $foo^5$ \n'
  </code></pre>