title: Regex select text outside two strings and .replace on the selection
body: <p>I have a string that looks like the following:</p>
  
  <pre><code>"This is a test [Text that (cannot) be changed]. But (this) can be changed."
  </code></pre>
  
  <p>I want to replace the strings inside <code>(</code> and <code>)</code> with html but not when they are inside <code>[ ]</code>. I want to replace all text within <code>[ ]</code> with a different html. My final result would look like the following.</p>
  
  <pre><code>"This is a test &lt;p&gt;Text that (cannot) be changed&lt;/p&gt;". But &lt;b&gt;this&lt;/b&gt; can be changed."
  </code></pre>
  
  <p>I created an expression that could select everything outside the <code>[ ]</code> strings. But how can I perform replace to this selected text only? To select everything outside <code>[ ]</code> I use this:</p>
  
  <pre><code>([^\[\]]+)(?:\s|$|\[)
  </code></pre>
  
  <p>This selects all text outside <code>[</code> and <code>]</code>. I want to perform regex replace for <code>( )</code> on this selected text only.</p>