silkfire Posted March 13, 2011 Share Posted March 13, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/230511-name-capturing-regex/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.