Page 1 of 1

Regex for name until bracket or end

Posted: Sun Apr 19, 2015 6:05 pm
by parakeet
I am dealing with input that is a string containing a full name, many times over.
I am using regex to split the full name in to...
  • First name: ^\S*
  • Middle name: \s+(.*\b)\s+
  • Last name: \S+$
But full names come in a variety of formats. One tricky pest is a full name with brackets, in the form "Ceri Tinine (née Jones)". I don't need " (née Jones)". And this throws off the middle and last name detection above. I only want to split "Ceri Tinine" in to first, middle and last names.

So, I need to reconstruct the regexs above so that each match is made on a full-name string that first looks to stop at the space preceding "(" or, else, the end of the full-name string.

How do I effectively combine these?

I am only just learning this stuff. No PHP needed - I only want to do this in regex if possible.

Many thanks.

Re: Regex for name until bracket or end

Posted: Mon Apr 20, 2015 5:02 pm
by Christopher
Please post the regexp that you have developed.