title: How to explain "$1,$2" in JavaScript when using regular expression?
body: <p>A piece of JavaScript code is as follows:</p>
  <pre><code>num = &quot;11222333&quot;;
  re = /(\d+)(\d{3})/;
  re.test(num);
  num.replace(re, &quot;$1,$2&quot;);
  </code></pre>
  <p>I could not understand the grammar of <code>&quot;$1,$2&quot;</code>. The book from which this code comes says <code>$1</code> means <code>RegExp.$1</code>, <code>$2</code> means <code>RegExp.$2</code>. But these explanations lead to more questions:</p>
  <ol>
  <li><p>It is known that in JavaScript, the name of variables should begin with letter or _, how can <code>$1</code> be a valid name of member variable of RegExp here?</p>
  </li>
  <li><p>If I input <code>$1</code>, the command line says it is not defined; if I input <code>&quot;$1&quot;</code>, the command line only echoes <code>$1</code>, not 11222. So, how does the replace method know what <code>&quot;$1,$2&quot;</code> mean?</p>
  </li>
  </ol>
  <p>Thank you.</p>