Replace character if not preceded nor followed by same character
<p>I am trying to replace non-consecutive single quotes in a string with two consecutive quotes. </p>

<p><strong>Examples (in/out)</strong></p>

<ul>
<li><code>"abc'def"</code> --> <code>"abc''def"</code></li>
<li><code>"abc''de'f"</code> --> <code>"abc''de''f"</code></li>
<li>etc.</li>
</ul>

<p>Javascript doesn't support lookbehinds, so the following regular expression I'd use with Java (well, more or less) will <strong>not</strong> compile: </p>

<pre><code>myString.replace(/(?&lt;!)'(?!'))/g, "''");
</code></pre>

<p>I have looked around SO and some answers advise using a non-capturing group containing a custom character class negating the character that would otherwise be in the negative lookbehind:</p>

<pre><code>myString.replace(/(?:[^'])'(?!'))/g, "''");
</code></pre>

<p>However, that will not do either: it will successfully not replace the two consecutive single quotes, but in the <code>"abc''de'f"</code> example, it will "eat" the <code>f</code> when replacing the next single quote with two consecutive single quotes, ending up in:</p>

<p><code>"abc''de''gh"</code> (see it's missing the <code>f</code>!)</p>

<p><strong>Questions</strong></p>

<ul>
<li>Is there a suitable regex-based solution for this problem?</li>
<li>If not, should I just go with a barbaric iteration and indexing of all the input string's characters and painfully build another string from it (please no)?</li>
</ul>