I am trying to extract firstname and lastname from a string. User can write inside my input the following: FirstName, FirstName LastName (sometimes full name, sometimes only firstname).
This is my regular expression, but it doesn't cover all the situations:
preg_match('/^(?<lastName>[^\s]+)[\s](?<firstName>.+)$/', $input, $matches);
This code will work for input like: A B, A B C D E, but not for A.
10x.