$ ./guess_the_languageRegex
Regex · medium · #24

What does this expression return?

'John Smith'.replace(/(\w+) (\w+)/, '$2, $1')
  1. 'Smith, John'
  2. 'John, Smith'
  3. '$2, $1'
  4. 'Smith John'
$1 and $2 in the replacement string insert the captured groups.
Play Regex ▸