I am trying to get the first and last name from a column using regex but I'm stumped.
I'm trying:
select
substring('SMIRTH JR, DAVID ALLEN', '^[^ ,]+') as namemodified
it should return
SMIRTH, DAVID
but it only returns the last name. I can't figure out how to get both.
I also need it to work for:
SMIRTHJR, DAVID ALLEN
since the data isn't very clean. Any ideas?
select regexp_replace('SMIRTH, DAVID ALLEN', '^([^,\s]+?)([JS]R)?\y[^,]*,\s*(\S+\y).*$', '\3, \1')