JSFiddle - React, Tailwind, and code Playground
JavaScript
var subject = 'This (is) a test [Then some text that (cannot) (be) changed]. But (this) (can) be changed.';
var regex = /(?:^|])([^\[]*)(?:\n|$|\[)/g;
var replace = subject.replace(regex, function(match, p1)
{
return match.replace(/\(/g, '<b>').replace(/\)/g, '</b>');
});
console.log(replace);
// This <b>is</b> a test [Then some text that (cannot) (be) changed]. But <b>this</b> <b>can</b> be changed.