I have a preg_match()
to try and capture math problems, but it's only working partially. While it capture the 'plus' and the last 'one', it doesn't capture the first 'one' for some reason. What am I doing wrong?
$string = "one plus one";
if (preg_match("~([0-9]|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety|hundred|thousand|million|\-| )+(\+|\-|\*|\/|plus|add|minus|subtract|time|multiply|divide)([0-9]|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen|eighteen|nineteen|twenty|thirty|forty|fifty|sixty|seventy|eighty|ninety|hundred|thousand|million|\-| )+~", $string, $match)) {
print_r($match);
}
Result:
Array ( [0] => one plus one [1] => [2] => plus [3] => one )
Expected Result:
Array ( [0] => one plus one [1] => one [2] => plus [3] => one )