I am trying to extract substrings from a long string in python3
def get_data(text):
initials = text.split()[1]
names = re.search(initials+'(.*)EMP',text).group(1).lstrip().title()
return initials, names
I need the following outputs
x,y = get_data('J JS JOHN SMITH EMP 223456')
JS
John Smith
x,y = get_data('J JB JOE BLOGGS CONT 223456')
JB
Joe Bloggs
x,y = get_data('J JS JOHN SMITH 223456')
JS
John Smith
I can do it with either EMP or CONT but am struggling to do it with EMP OR CONT OR 'None' I'm new to regex hence help appreciated