title: How do I choose between valid regular expressions - example from eloquent javascript, chapter 9
body: <p><a href="http://eloquentjavascript.net/09_regexp.html" rel="nofollow">Chapter 9 of Haverbeke's <em>Eloquent Javascript</em></a> contains the following regex example:</p>
  
  <pre><code>console.log(
    "Hopper, Grace\nMcCarthy, John\nRitchie, Dennis"
      .replace(/([\w ]+), ([\w ]+)/g, "$2 $1"));
  
  //   OUTPUT:
  // → Grace Hopper
  //   John McCarthy
  //   Dennis Ritchie
  </code></pre>
  
  <p>However, I am not sure why he uses square brackets or why he has a space after the <code>\w</code>. The following regular expressions seem to produce identical output:</p>
  
  <pre><code>console.log(
    "Hopper, Grace\nMcCarthy, John\nRitchie, Dennis"
      .replace(/([\w]+), ([\w]+)/g, "$2 $1"));       // Spaces removed.
  
  console.log(
    "Hopper, Grace\nMcCarthy, John\nRitchie, Dennis"
      .replace(/(\w+), (\w+)/g, "$2 $1"));           // No brackets or spaces.
  </code></pre>
  
  <p>JSFiddle <a href="https://jsfiddle.net/aq53t1qL/" rel="nofollow">HERE</a></p>
  
  <p><strong>TO SUMMARIZE</strong></p>
  
  <ol>
  <li>From a performance or best-practices perspective, are there any differences among the three regular expressions given above?</li>
  <li>If so, what are they?</li>
  <li>If not, how should I distinguish between them when making coding decisions?</li>
  </ol>