You can use the following regex:
/^.*?(?=\s*[^\s\p{L}])/
$str = "Go Forty Go (IRE) 471 -> Go Forty Go";
$str2 = "Pearl Noir 15528258 D3 -> Pearl Noir";
$str3 = "Synonym (ITY) 1793158-00 D1 -> Synonym";
preg_match('/^.*?(?=\s*[^\s\p{L}])/', $str, $match);
echo $match[0] . PHP_EOL;
preg_match('/^.*?(?=\s*[^\s\p{L}])/', $str2, $match1);
echo $match1[0] . PHP_EOL;
preg_match('/^.*?(?=\s*[^\s\p{L}])/', $str3, $match2);
echo $match2[0] . PHP_EOL;
See IDEONE code
Output:
Go Forty Go
Pearl Noir
Synonym
The "core" of the regex is (?=\s*[^\s\p{L}])
look-ahead that makes matching stop at a non-letter or space preceded with optional whitespace (to trim the output).
If you have Unicode letters in your input, add u
flag:
/^.*?(?=\s*[^\s\p{L}])/u
"; – emma perkins Jul 16 '15 at 10:29