Regex for name until bracket or end

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
parakeet
Forum Newbie
Posts: 1
Joined: Sun Apr 19, 2015 5:55 pm

Regex for name until bracket or end

Post 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.
User avatar
Christopher
Site Administrator
Posts: 13595
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Regex for name until bracket or end

Post by Christopher »

Please post the regexp that you have developed.
(#10850)
Post Reply