$re = '/^(?>[^\w\n]*(\w++)(?=.*\R(\2?+[^\w\n]*\1\b)))+[^\w\n]*\R(?=\2[^\w\n]*$)/mi';
$str = 'Rough work iconoclasm but the only way to get the truth. Oliver Wendell Holmes
Rough work, iconoclasm, but the only way to get the truth. Oliver Wendell Holmes
Rule No. 1: Never lose money. Rule No. 2: Never forget rule No. 1. Warren Buffett
Rule No.1: Never lose money. Rule No.2: Never forget rule No.1. Warren Buffett
Self-esteem isn\'t everything, it\'s just that there\'s nothing without it. Gloria Steinem
Self-esteem isn\'t everything it\'s just that there\'s nothing without it. Gloria Steinem
You said she\'s a senior? Babe we\'re all crazy.
You said, she\'s a senior! Babe we\'re ALL crazy.
You said, she\'s a senior? Babe we\'re ALL crazy!
a
a a
a a a
a
a b
a b c
a b
a';
$subst = "";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
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