I have a string and a list of names that I compare the string against using preg_match_all
which returns the matches. However in the list of names, some names are first-name OR last-name only while others are both. See my example below.
$names = 'jon|jon snow|lana|smith|lana smith|megan';
$string = 'Jon Snow and Lana Smith met up with Lana and Megan.';
preg_match_all("~\b($names)\b~i", $string, $matches);
The above example with my current expression returns all the names. Which isn't what I want.
What I want returned: jon snow, lana smith, lana, megan.
What I don't want returned: jon, smith