I am following the Elequent Javacript's website page on regular expressions and getting a little frustrated.
The page shows this example which swaps first and last names whilst removing commas:
var names = "Picasso, Pablo\nGauguin, Paul\nVan Gogh, Vincent\n";
document.writeln(names.replace(/([\w ]+), ([\w ]+)/g, "$2 $1"));
The author briefly explains what it does, but expends very little effort explaining why it works, and what the key features of this example are.
Can anyone help my fathom what ("$1 and $2) are and what they are referencing and why