Remove the () from the regex, seems to work for me:
<?php
function translate($content,$lang){
$l = $lang;
$pattern = array('en'=>'/\{\{.[^\}\}]*\|\|/','cy'=>'/\|\|.[^\{\{]*\}\}/'); # change this
$brackets = array('en'=>'}}','cy'=>'{{');
$content = preg_replace($pattern[$l],'',$content);
$content = str_replace($brackets[$l],'',$content);
return $content;
}
$content=<<<CONTENT
<p>{{Dyma destun (cy example) rand ||Here's some text en (example) rand}}</p>
CONTENT;
echo translate($content,'en');
echo "\n";
?>
or I'm missing the problem? o_o'