title: How to capture second to last match?
body: <p>I'm trying to use <code>RegExp</code> with <code>String.replace</code> to replace the second to last occurrence of a word in a space-separated string.</p>
  <p>I don't understand why my code isn't working.  I have parentheses around the correct match, so why is it replacing the match of the entire <code>RegExp</code> instead of just what's inside the capture group?</p>
  <pre class="lang-js prettyprint-override"><code>const re = /(\w+) \w+$/;
  const string = 'john deer senior third';
  const result = string.replace(re, match =&gt; `[${match}]`);
  
  console.log(result); // john deer [senior third]
  </code></pre>
  <p>Desired result:</p>
  <pre class="lang-js prettyprint-override"><code>john deer [senior] third
  </code></pre>