1
我試圖在XLIFF文件上運行一系列模式。示例:永不停止使用正則表達式的循環
<trans-unit id="1">
<source> I like "sausages". </source>
<target> J'aime bien les « sausices » </target>
</trans-unit>
<trans-unit id="2">
<source> I like "sausages". </source>
<target> J'aime bien les «sausices» </target>
</trans-unit>
我解析文件,然後在每個目標元素上運行每個模式。
foreach($patterns as $p) {
if (preg_match($p['find'], $tu[0]->target, $dummy)) {
do {
$targetText = $tu[0]->target;
$tu[0]->target = preg_replace($p['find'], $p['repl'], $targetText, -1, $count);
} while ($count);
}
}
例如,我有patters的數組:
$patterns[1] = array(
'find' => "/[«‹]\K(?!\x{00A0})\s/imu",
'repl' => " "
);
$patterns[2] = array(
'find' => "/[«‹]\K(?!\p{Zs})/imu",
'repl' => " "
);
構成形式1應該匹配上述反式單元1,和模式2應與反式單元2模式1個工作正常,但如果我運行模式2(只有或兩者),循環永遠不會結束。替換基本上用«或<(模式1)代替了一個狹窄的空白區域的正常(打破)空間,或者根本沒有空間插入它(模式1)。
我會說這個問題與第二個正則表達式有關,但我無法弄清楚這個表達式有什麼問題。有小費嗎?
有時人們樣本數據添加到他們的問題.... – Andreas
對不起,我我以前不覺得這將是相關的。現在補充,謝謝! – msoutopico
與這個問題無關,但在法國它寫的'saucisse' – Toto