$re = '/(?i)(?:\w+\W+){0,9}?(?=.*(?:plot).*|.*(?:over).*)(?:\w+\W+){0,9}?(?=Charlie|Muir|Charlie Muir)\K(?:(?:Charlie|Muir|Charlie Muir)\s+)+/m';
$str = 'POSITIVE TESTING
1.
Charlie Muir was over the moon.
next next next next next next next next next next next next next next
Charlie Muir was in the plot .
next next next next next next next next next next next next next next
2.
Charlie was over the moon.
next next next next next next next next next next next next next next
Charlie was in the plot .
next next next next next next next next next next next next next next
3.
Mr. Charlie was over the moon.
next next next next next next next next next next next next next next
Mr.Muir was in the plot.
next next next next next next next next next next next next next next
4.
When Charlie saw the letter , Charlie was over the moon.
next next next next next next next next next next next next next next
When Charlie saw the letter, ChaRLIE was walking in the plot.
next next next next next next next next next next next next next next
5.
When Charlie Muir saw letter , Charlie Muir was over the moon.
next next next next next next next next next next next next next next
When Charlie Muir saw letter, ChaRLIE MUIR was walking in plot.
next next next next next next next next next next next next next next
6.
When Muir saw letter , Mr.Muir was over the moon.
next next next next next next next next next next next next next next
When Mr.MUIR saw letter, Mr.CharliE was walking in plot.
next next next next next next next next next next next next next next
7.
When Muir saw letter , Mr.Charlie Muir was over the moon.
next next next next next next next next next next next next next next
When Mr.Charlie saw letter, Mr.MUIR was walking in plot.
next next next next next next next next next next next next next next
8.
Charlie Muir was Over the moon.
next next next next next next next next next next next next next next
Charlie Muir was in the PLOT .
next next next next next next next next next next next next next next
9.
He,Charlie and Muir were OVEr the moon.
next next next next next next next next next next next next next next
Charlie and MR.MUIR were in the ploT .
next next next next next next next next next next next next next next
10.
Over the moon was Charlie.
next next next next next next next next next next next next next next
Plot was far away from Charlie.
next next next next next next next next next next next next next next
11.
OVER the moon was Charlie Muir.
next next next next next next next next next next next next next next
Plot was far away from CHARLIE MUIR.
next next next next next next next next next next next next next next
12.
over the moon were Charlie and Muir.
next next next next next next next next next next next next next next
Plot was far away from Charlie and Muir.
next next next next next next next next next next next next next next
13.
Over the moon was Mr.Muir whose first name is Charlie.
next next next next next next next next next next next next next next
PLOT was far away from Charlie whose last name is MUIR.
next next next next next next next next next next next next next next
14.
OVER the moon was MUIR who is also charlie Muir.
next next next next next next next next next next next next next next
plot was far away from MUIR who is also CHarlie Muir.
next next next next next next next next next next next next next next
---------------------------------------------------------------------
POSITVE / NEGATIVE TESTING
15.
Charlie knew when CHARLIE saw the letter that he would be over the moon after reading it.
next next next next next next next next next next next next next next
Charlie knew what the letter would contain when Charlie was reading it while walking in the plot.
next next next next next next next next next next next next next next
16.
Charlie knew when Charlie and muir saw the letter that they would be over the moon
next next next next next next next next next next next next next next
Charlie knew when Charlie and Muir saw the letter that they would be in the plot
next next next next next next next next next next next next next next
17.
Charlie knew when Charlie Muir saw the letter that they would be over the moon
next next next next next next next next next next next next next next
Charlie knew when Charlie Muir saw the letter that they would be in the plot
next next next next next next next next next next next next next next
18.
over the moon was Charlie Muir who is also known simply as CHARLIE.
next next next next next next next next next next next next next next
The plot was far away from Charlie Muir who is also known simply as CHARLIE.
next next next next next next next next next next next next next next
19.
OVER the moon was Mr.ChaRlie and Muir who are together known as the MuIr Brothers.
next next next next next next next next next next next next next next
The plot was far away from Charlie and Muir who are together known as the MUIR Brothers.
next next next next next next next next next next next next next next
-----------------------------------------------------------------------
NEGATIVE TESTING
20.
Charlie Muir , after receiving and reading letter was addressed to him , was over the moon.
next next next next next next next next next next next next next next
Charlie Muir received and read the letter was addressed to him in plot.
next next next next next next next next next next next next next next
';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php