Have been trying for a while, to match the last word of a sentence:
select regexp_matches('My name is Harry Potter', '[^ ]+$');
returned {Potter}
to try to match the last two words:
select regexp_matches('My name is Harry Potter', '[^ ]s+[^ ]+$');
failed.
select regexp_matches('My name is Harry Potter', '(.*?)s+(.*?)$');
Did not word as intended either.
Any insights?
See Question&Answers more detail:os