What does this expression return?
'John Smith'.replace(/(\w+) (\w+)/, '$2, $1')
- 'Smith, John'
- 'John, Smith'
- '$2, $1'
- 'Smith John'
$1 and $2 in the replacement string insert the captured groups.'John Smith'.replace(/(\w+) (\w+)/, '$2, $1')
$1 and $2 in the replacement string insert the captured groups.