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

Popular posts from this blog

rest - Spring boot: Request method 'PUT' not supported -

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

symfony - imagine_filter() not generating the correct url in LiipImagineBundle -