Hello Everyone,

As the title implies I need help extracting a name out of a string, my knolwedge of regular expressions is pretty limited. The strings I will be working with will look like this:

12345       Aragon  Denvil L.   123-1234    A123456 AragonD AragonAD@fake.mail.us   1000001234  ABC-ABC 123ABCD123  ABCD 1234 A1234 ABC12345A1  AB123AB 17-Feb-12   
54321   Mgmt    Chan    Jackie  123-4321    ABC4321 ChanJ   ChanJ@fake.mail.us  0   ABC-ABC 123ABCD123  ABCD 1234 A1234 ABC12345A1  AB123AB 17-Feb-12

From the first line I would be trying to extract "Aragon Denvil L." and from the second "Mgmt Chan Jackie". Worst case scenario I could maybe get away with just extracting "AragonD" and "ChanJ". I have managed to extract the emails and phone numbers from the strings, but no clue where to start for getting the names out.
Any and all help is greatly appreciated. Thanks in advance!

Member Avatar for diafol

I'm rubbish at regex. Maybe something like:

$str = "12345       Aragon  Denvil L.   123-1234    A123456 AragonD AragonAD@fake.mail.us   1000001234  ABC-ABC 123ABCD123  ABCD 1234 A1234 ABC12345A1  AB123AB 17-Feb-12";

$pattern = "/([^\d]+)/";

preg_match($pattern,$str,$matches);

$name = trim($matches[1]);

echo $name;

That works perfectly! Thank you so much!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.