Is there an amazing RegEx or method in C# that might achieve this for me?
Someone types a string into a ‘Full name’ field, and I need to break it into:
Title
Firstname
Middle
Surname
Suffix
But the user can type “John Smith”, so it needs to put John into First Name, and Smith into Surname. A person can type Mr John Smith (I have a list of known titles and suffixes), so if the first string is a title, it goes into Title field.
A perfect example would be:
Mr John Campbell Smith Jr
But, they could have:
Mr and Mrs John and Mary Smith
So the title would be Mr and Mrs, the firstname would be John and Mary, and the surname is Smith (They can use either “And” or “&” as a joiner)
I’m guiessing this is too complex for regex, but I was hoping someone may have an idea?
Alright, here is a program that I think will do the job for you. You may of course have to make some modifications because I made some assumptions based on your question, but this should certainly get you started in the right direction.
Some of those assumptions are as follows:
I threw a lot of different names at it, but there are certainly more possibilities, I didn’t spend any more than 30 minutes on this so it’s not fully tested.