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

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -