匹配两个单词之间的所有内容,而匹配的最后一个单词是可选的

I need to capture everything between 'one' and 'four', the 'four' being optional. We don't know what's between 'one' and 'four'. I tried matching it, but not getting the right result. What am I doing wrong?

$text = "one two three four five six seven eight nine ten";
preg_match("~one( .+)(four)?~i", $text, $match);

print_r($match);

Result:

Array ( [0] => one two three four five six seven eight nine ten [1] => two three four five six seven eight nine ten )

Need Result:

Array ( [0] => one two three four five six seven eight nine ten [1] => two three [3] => four)

PS: Yes, the 'four' needs to be optional.

Here you need to use alternation operator.

one(( .+)(four).*|.*)

DEMO

By default repeat operators (like "?", "*", "+" or {n,m}) are greedy - they wil try to match as much symbols as they can. You can read more on this behalf here: What do lazy and greedy mean in the context of regular expressions?

To make them not greedy add "?" after them. Like this: "~one( .+?)(four)?~i"