title: Manipulating JavaScript's parenthesized substring matches
body: <p>Example taken from <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Working_with_Regular_Expressions/Using_Parenthesized_Substring_Matches" rel="nofollow noreferrer">Mozilla's help page</a></p>
  <pre><code>&lt;script type=&quot;text/javascript&quot;&gt;
    re = /(\w+)\s(\w+)/;
    str = &quot;John Smith&quot;;
    newstr = str.replace(re, &quot;$2, $1&quot;);
    document.write(newstr);
  &lt;/script&gt;
  </code></pre>
  <p>Is it possible to further manipulate the substring match directly in any way? Is there any way to, for example, capitalize just the word Smith in one line here? Can I pass the value in $2 to a function that capitalizes and returns a value and then use it directly here?</p>
  <p>And if not possible in one line, is there an easy solution to turn &quot;John Smith&quot; into &quot;SMITH, John&quot;?</p>
  <p>Trying to figure this out but not coming up with the right syntax.</p>