Jump to content

Name-capturing regex


silkfire

Recommended Posts

I've hit a standstill with a regex I'm developing it seems pretty simple but it's not really working :/

 

It needs to capture a name and grab the very first name and make initials out of the following names (middle and last names).

 

Regex right now looks like:

 

preg_match_all('#^([^\s]+)(?: (.)[^\s]+)+$#m', $string, $matches, PREG_SET_ORDER);

 

I want the regex to work both with multiline and single line (I'm testing on a big list of names separated with newline).

 

So if the name is George Walker Bush I want to capture George W B. If it's Laura Bush, I want Laura B, if it's George Herbert Walker Bush I want George H W B, etc.

 

Thanks in advance.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.