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

...
`, and `(...)` by `...`? (Except when `(...)` is inside `[...]`) – Sébastien Jan 27 '15 at 11:32