title: Regex replacement for SQL using sed
body: <p>I have a file containing many SQL statements and need to add escape characters, using SED, for single quotes withing the SQL statements. Consider the following:</p>
  <pre><code>INSERT INTO MYTABLE VALUES (1,'some text','Drink at O'Briens');
  </code></pre>
  <p>In the above we need to escape the single quote in <code>O'Briens</code>. Using regex I can find the string using <code>[a-zA-Z ]'[a-zA-Z ]</code>.</p>
  <p>So this will find the 3 characters of interest, however if I do the following sed command:</p>
  <pre><code>sed -i &quot;s/[a-zA-Z ]'[a-zA-Z ]/''/g&quot; file.sql
  </code></pre>
  <p>This, however, removes the <code>O</code> and the <code>B</code> so I end up with:</p>
  <pre><code>INSERT INTO MYTABLE VALUES (1,'some text','Drink at ''riens');
  </code></pre>
  <p>How do I isolate/reference the O and the B so the string becomes:</p>
  <pre><code>INSERT INTO MYTABLE VALUES (1,'some text','Drink at O''Briens');
  </code></pre>