Compute replacements dynamically from captures.
Section: JavaScript Regex APIs
replace() callback
javascript
javascript
text.replace(/(\w+),\s*(\w+)/g, (_, last, first) => `${first} ${last}`)Explanation
Useful for reformatting structured text.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing JavaScript Regex APIs