title: Regex to replace text enclosed in brackets
body: <p>The runtime is NodeJS, I'm trying to replace the text <code>$Contact</code> with a name. But I also need the ability to capture words around the term enclosed in curly brackets <code>{}</code>:</p>
  <pre><code>Where Name = John:
    My name is $Contact =&gt; My name is John
    Hello {I am $Contact} =&gt; Hello I am John
  
  Where Name = null:
    My name is $Contact =&gt; My name is 
    Hello {I am $Contact} =&gt; Hello
  </code></pre>
  <p>The idea is to replace the <code>$Contact</code> qualifier with a string, and OPTIONALLY the text enclosed in brackets is only displayed if the string is not empty. The use of curly brackets is optional.</p>
  <pre><code>// m = Message template (Hello {I am $Contact})
  // qualifier = $Contact
  // value = value to replace with
  
  const replaceQualifier = (m, qualifier, value) =&gt;
      m.replace(new RegExp('\\{?(.*?)\\' + qualifier + '(.*?)\\}?', 'g'), value ? `$1${value}$2` : '');
  </code></pre>
  <p>It seems to work for qualifiers without curly brackets but not with curly brackets.</p>