I've created a regular expression in C# but now I'm struggling when trying to run it in PHP. I presumed they'd work the same but obviously not. Does anyone know what needs to be changed below to get it working?
The idea is to make sure that the string is in the format "Firstname Lastname (Company Name)" and then to extract the various parts of the string.
C# code:
string patternName = @"(\w+\s*)(\w+\s+)+";
string patternCompany = @"\((.+\s*)+\)";
string data = "Firstname Lastname (Company Name)";
Match name = Regex.Match(data, patternName);
Match company = Regex.Match(data, patternCompany);
Console.WriteLine(name.ToString());
Console.WriteLine(company.ToString());
Console.ReadLine();
PHP code (not working as expected):
$patternName = "/(\w+\s*)(\w+\s+)+/";
$patternCompany = "/\((.+\s*)+\)/";
$str = "Firstname Lastname (Company Name)";
preg_match($patternName, $str, $nameMatches);
preg_match($patternCompany, $str, $companyMatches);
print_r($nameMatches);
print_r($companyMatches);