1. Rearranging Name Formats with re.sub
Backend DeveloperBackground
A developer needs to convert full names formatted as 'First Last' into 'Last, First' across customer records.
Problem
Verify that named groups extract correctly and that the re.sub replacement template formats the output as expected.
How to use
Input the named pattern `(?P<first>\w+)\s+(?P<last>\w+)`, provide sample names in the test string, and add `\g<last>, \g<first>` to the replacement template.
Pattern: (?P<first>\w+)\s+(?P<last>\w+), Replacement: \g<last>, \g<first>, Flags: gOutcome
Both names are matched and converted into the 'Last, First' format with complete Python snippet generation.