Names in the form Nelson, Craig T. need to be split into
AN Nelson
FN Craig
IT C.T.
IT means initials, note the first initial is the first letter of FN, first name.
I already have a bunch of patterns in regex. For this one, I suspect regex won't do, the reason being: you can't slice a backreference
import re
name = r'Nelson, Craig T.'
pat = r'([^\W\d_]+),\s([^\W\d_]+\s?)\s(([A-Z]\.?)+)\s?$'
rep = r'AN \1\nVN \2\nsf \3\n'
split = re.sub(pat, rep, name)
print(split)
will produce:
AN Nelson
FN Craig
IT T.
Ideally I'd somehow slice the \2, add a full stop and stick \3 behind it. I think this is not possible with regex and I should use a string operation, HOWEVER, it wouldn't be the first time I'd learn a trick here that I hadn't deduced from the documentation. (Thanks guys.)