I am looking to replace all instances of text within brackets, including the brackets themselves, in a given string. The specific text to be replaced will be stored in a variable in Javascript. Using a simple regex in a replace method won't work due to the inclusion of brackets.
For example, if we want to replace "[test] [teste] test [hello]" with the value stored in a variable as "hi", the expected output would be "hi hi test [hello]".