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

c++11 - Intel compiler and "cannot have an in-class initializer" when using constexpr -

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

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -