php - Never ending do-while loop with regex -
i trying run series of patterns on xliff file. sample:
<trans-unit id="1"> <source> "sausages". </source> <target> j'aime bien les « sausices » </target> </trans-unit> <trans-unit id="2"> <source> "sausages". </source> <target> j'aime bien les «sausices» </target> </trans-unit>
i parse file, , run each pattern on each target element.
foreach($patterns $p) { if (preg_match($p['find'], $tu[0]->target, $dummy)) { { $targettext = $tu[0]->target; $tu[0]->target = preg_replace($p['find'], $p['repl'], $targettext, -1, $count); } while ($count); } }
for example, have array patters:
$patterns[1] = array( 'find' => "/[«‹]\k(?!\x{00a0})\s/imu", 'repl' => " " ); $patterns[2] = array( 'find' => "/[«‹]\k(?!\p{zs})/imu", 'repl' => " " );
patter 1 should match trans-unit 1 above, , pattern 2 should match trans-unit 2. pattern 1 works fine, if run pattern 2 (only or both) loop never ends. replacement replaces normal (breaking) space after « or ‹ (pattern 1) narrow breaking space or inserts if there's no space @ (pattern 1).
i issue has second regex, can't figure out wrong expression. tips?
the \p{zs}
pattern not match  
, therefore add  
lookahead condition in second pattern:
'find' => "/[«‹]\k(?!\p{zs}| )/iu",) ^^^^^^^
Comments
Post a Comment