I remember
Prestashop did some rewriting/editing in .htaccess when enabling/changing seo urls or other settings like compression and stuff, so it's possible.
You can do something like getting the file's content > put it in a variable > search and replace/remove what you need > rewrite the file.
Here, I use this function to write .php files in a script that helps translate/create locale files. Not tested under *nix.
[syntaxhighlighter brush=php,first-line=1,highlight=0,collapse=false,html-script=false]function create_file($ofile, $content) {
$oFile = fopen($ofile, 'w'
;
if (flock($oFile, LOCK_EX)) {
fwrite($oFile, $content);
flock($oFile, LOCK_UN);
} else {
echo "<div class='admin-message'>Ooops! Something went wrong while atempting to write the file.<br />Please try again.</div>";
}
//Done writing, close file
fclose($oFile);
}[/syntaxhighlighter]
I could help with regex if you give more details about what are trying to achieve.