$s = "aaa";
echo preg_replace('/^(.*?)a$/s', "$1_", $s);
$s = "\t\t\t";
echo preg_replace('/^(.*?)\t$/s', "$1_", $s);
$s = "\n\n\n";
echo preg_replace('/^(.*?)\n$/s', "$1_", $s);
The first one prints
aa_
and the second one
\t\t_
But the last one prints
\n_\n
Why?