I have a regex that matches 2 patterns with 1 pattern in the front or back, but the first array return 2 empty indexes. Why is it doing that, and how would I stop it from doing that?
$text = "i did";
preg_match("~(?:(did) (.+)|(.+) (did))~", $text, $match);
print_r($match);
echo "<br>";
$text = "did i";
preg_match("~(?:(did) (.+)|(.+) (did))~", $text, $match);
print_r($match);
Result:
Array ( [0] => i did [1] => [2] => [3] => i [4] => did )
Array ( [0] => did i [1] => did [2] => i )
Want Result:
Array ( [0] => i did [1] => i [2] => did )
Array ( [0] => did i [1] => did [2] => i )