Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
import re text = "John Smith, Jane Doe" # Swap first and last name result = re.sub(r"(\w+) (\w+)", r"\2, \1", text) print(result) # Smith, John, Doe, Jane
Result
Open