trying to get Textrange (n words before and after) a search string (myself)
$text = 'Me, my dog and “myself“ are going on a vacation. Irene and myself are broke. Myself is here :P John and myself!';
preg_match_all("/(?:[^ ]+ ){0,2}(?:[“'"(‘. ])myself(?:[“'")‘. ])(?: [^ ]+){0,2}/", $text, $matches);
this gives me matches :
• dog and “myself“ are going
• myself
But it should be:
• dog and “myself“ are going
• Irene and myself are broke
• John and myself!
Please help me find all matches as text range 2 words before and 2 words after. no matter if there is a special char or whitespace before or after search string (myself) or 'myself' or “myself“ ...
thanks.Sepp