JSFiddle - React, Tailwind, and code Playground
by bean_baggy
JavaScript
var stringToGoIntoTheRegex = "abc";
var regex = new RegExp("\\[" + stringToGoIntoTheRegex + "\\]", "g");
// at this point, the line above is the same as: var regex = /#abc#/g;
var input = "Hello this is [abc] some #abc# stuff.";
var output = input.replace(regex, "!!");
alert(output); // Hello this is !! some !! stuff.