title: JavaScript regular expression having a weird behaviour
body: <p>I'm currently making a scripting language for a Discord bot I'm maintaining and I'm facing a weird issue. The following code takes a string as input (<code>I think {if:3|=|0|you are|TechRax is} {range:1|100}</code>), uses the <code>match</code> method of the string to get all functions (expression: <code>/\{(.*?):(.*?)\}/g</code>) from the string. Then using a <code>forEach</code>, I process all of these matches then I replace the matched content with the result on the string, using the <code>replace</code> method.</p>
  
  <p>Here is the code I use:</p>
  
  <pre><code>let newString = 'I think {if:3|=|0|you are|TechRax is} {range:1|100}';
  const functionPattern = /\{(.*?):(.*?)\}/g;
  const foundFunctions = newString.match(functionPattern);
  if (!foundFunctions) throw new Error('No function found');
  
  foundFunctions.forEach((fn) =&gt; {
    const parsedInput = functionPattern.exec(fn); // = null once the second iteration begins... ? only the first one work. Same issue if I invert the function orders (first works, second and + no)
    if (!parsedInput || !parsedInput[1] || !parsedInput[2]) return;
  
    try {
      /*const customFunction = new (require(`../../Production/Tags/${parsedInput[1]}`))(this.client, context, contextType);
      if (!customFunction) return;
  
      const result = customFunction.run(parsedInput[2].split('|'));*/
      const result = 'Stack Overflow test';
      newString = newString.replace(fn, result);
    } catch (e) {
      newString = newString.replace(fn, e);
    }
  });
  
  // Print newString here (depends if you're on browser or node)
  </code></pre>
  
  <p>In this context, <code>this.client.constants.functionPattern = /\{(.*?):(.*?)\}/g</code>, <code>foundFunctions = ['{if:4|=|0|you are|alien is}', '{range:1|100}']</code> and <code>newString = 'I think {if:{argslen}|=|0|you are|{args} is} {range:1|100}'</code>.</p>
  
  <p>Now let's start describing the behaviour, the <strong>first iteration</strong> goes well: the function module gets imported, it gets processed and the final content gets replaced on the string.</p>
  
  <p>The problem concerns the <strong>second</strong> one (and all others), the <code>exec</code> method of the function expression returns <code>null</code>. I do not understand this at all, first I thought it was a kind of bug with my RegExp, maybe <code>{random:1|100}</code> was not matching but no because it works perfectly on Regexr.com and... the weirdest: if I eval it (<code>/\{(.*?):(.*?)\}/g.exec('{range:1|100}</code>), it doesn't return <code>null</code> but the actual result I expect.</p>
  
  <p>I guess I'm wrong somewhere but after passing some hours on it I still do not get why it isn't working.
  I hope you'll be able to help me out, thanks!
  If you need any complementary information, I'm here.</p>