M
michael
Hello, I am bit new to using REGEX.. so I have data that looks like the
following all in one column called target_name and I need to separate
it out into First Name, Middle Name, Last Name, Title One, Title Two.
Examples
John Doe, MBA
John J Doe
John Doe
John Michael Doe,MFA,MS
I am having the most difficulty with the middle name spelled out vs the
last name.. There must be a way to either match from the first comma
back or the 3rd/2nd space back or the end, something like this --> [,[
]{2|3}$]? but that is not working... or any other suggestion would be
much appreciated.
I have done something like the below
SELECT
REGEXP_SUBSTR(c.TARGET_NAME,'^[A-z-]+') FIRST_NAME,
REGEXP_SUBSTR(c.TARGET_NAME,' [A-z-]+{1}\.? ') MIDDLE_NAME,
REGEXP_REPLACE(c.TARGET_NAME,' ([A-Z][a-z]+)[, $]?','\1')
LAST_NAME,
c.TARGET_NAME
FROM blah.mytable c;
following all in one column called target_name and I need to separate
it out into First Name, Middle Name, Last Name, Title One, Title Two.
Examples
John Doe, MBA
John J Doe
John Doe
John Michael Doe,MFA,MS
I am having the most difficulty with the middle name spelled out vs the
last name.. There must be a way to either match from the first comma
back or the 3rd/2nd space back or the end, something like this --> [,[
]{2|3}$]? but that is not working... or any other suggestion would be
much appreciated.
I have done something like the below
SELECT
REGEXP_SUBSTR(c.TARGET_NAME,'^[A-z-]+') FIRST_NAME,
REGEXP_SUBSTR(c.TARGET_NAME,' [A-z-]+{1}\.? ') MIDDLE_NAME,
REGEXP_REPLACE(c.TARGET_NAME,' ([A-Z][a-z]+)[, $]?','\1')
LAST_NAME,
c.TARGET_NAME
FROM blah.mytable c;