<p>I need to replace character (say) <strong>x</strong> with character (say) <strong>P</strong> in a string, but only if it is contained in a quoted substring.
An example makes it clearer:</p>

<pre><code>axbx'cxdxe'fxgh'ixj'k  -&gt; axbx'cPdPe'fxgh'iPj'k
</code></pre>

<p>Let's assume, for the sake of simplicity, that quotes always come in pairs. </p>

<p>The obvious way is to just process the string one character at a time (a simple state machine approach);<br>
however, I'm wondering if regular expressions can be used to do all the processing in one go.</p>

<p>My target language is C#, but I guess my question pertains to any language having builtin or library support for regular expressions.</p>

Not with plain regexp. Regular expressions have no "memory" so they cannot distinguish between being "inside" or "outside" quotes.
You need something more powerful, for example using
gema
it would be straighforward:
```
```
'<repl>'=$0
repl:x=P
```
```