title: Javascript replace opening and closing brackets
body: <p>I have a string of text, for example</p>
  
  <pre><code>[text1] [text2] [text3]
  </code></pre>
  
  <p>I want to replace "[" character with "${" and "]" character with  "}", but only in that case, when "[" is followed up by "]".</p>
  
  <p>For example</p>
  
  <pre><code>[text1] [[text2] [text3]
  </code></pre>
  
  <p>should result in</p>
  
  <pre><code>${text1} [${text2} ${text3}
  </code></pre>
  
  <p>How can I accomplish that with regex in Javascript?</p>
  
  <p>I wrote something like this</p>
  
  <pre><code>someString = someString.replace(/\[/g, "${");
  someString = someString.replace(/]/g, "}");
  </code></pre>
  
  <p>But it doesn't work for my problem, it just replaces every bracket.</p>