title: Why does this regex replacement not work for JavaScript, but instead only work for other engines?
body: <p>I want to build a JavaScript function that transforms text into another format, from this:</p>
  
  <pre><code>MATCH 1
  1.  [4-17]  `public direct`
  2.  [18-29] `routing.key`
  MATCH 2
  1.  [35-41] `direct`
  2.  [42-52] `routingkey`
  </code></pre>
  
  <p>To this:</p>
  
  <pre><code>MATCH 1: [Group 1: public direct] [Group 2: routing.key]
  MATCH 2: [Group 1: direct] [Group 2: routingkey]
  </code></pre>
  
  <p>I've been messing with this code in my Chrome browser console using regex replacements, however it will not replace anything. Here is one of the approaches I've tried, <code>a</code> is the test object, the problem is on the second replacement:</p>
  
  <pre><code>a = "MATCH 1 \n\
  1.  [4-17]  `public direct` \n\
  2.  [18-29] `routing.key` \n\
  MATCH 2 \n\
  1.  [35-41] `direct` \n\
  2.  [42-52] `routingkey`"
  
  var repl = a.replace(/^(MATCH\s\d+)\s*/gm, "$1: ")
              .replace(/(\d+)\.\s+\[[^]]+\]\s*`([^`]*)`\s*/g, "[Group $1: $2]")
              .replace(/(?=MATCH\s\d+: )/g, "\n")
  
  console.log(repl)
  </code></pre>
  
  <p>Studying regex101 demos, the pattern <code>/(\d+)\.\s+\[[^]]+\]\s*`([^`]*)`\s*/g</code> will <a href="http://regex101.com/r/gB3uR8/1#pcre" rel="nofollow">replace properly in PHP (PCRE)</a> <a href="http://regex101.com/r/gB3uR8/1#python" rel="nofollow">and Python</a>, but <a href="http://regex101.com/r/gB3uR8/1#javascript" rel="nofollow">not on JavaScript</a>.</p>
  
  <p>Why?</p>