Test, validate and match regular expressions
Matches from the start of a line, greedily consuming everything up to the last whitespace, then captures the final word (Unicode letters) together with a comma and the rest of the line. It's typically used for shortening names, e.g., capturing 'Smith, Jr.' from 'John A. Smith, Jr.' so the surname and suffix stay together. The \p{L} class handles accented and non-Latin letters, and the global flag lets it process every occurrence in the input.