regex - Match from the third word onwards in a string with PHP -
i'm trying return dolor sit amet
following string -
$title = 'lorem ipsum dolor sit amet'; preg_match('/^(?:\w+\s+){2}(.)+/', $title, $matches);
it's matching last letter.
you need put repetition operator inside group:
preg_match('/^(?:\w+\s+){2}(.+)/', $title, $matches);
otherwise, group captures 1 character.
Comments
Post a Comment