I don't follow you here.
If I enter a body of 'ok', then this works as expected. If I enter a body of 'ok ' then it still enters the if branch even though there is no match. That is correct; regardless of of a match has occurred, your code only checks if it fails outright which is from a bad pattern.
So according to the PHP manual and the code you have here, it is functioning as expected. You only get to the else branch if the pattern fails to compile.