Php 使用正则表达式永不结束do-while循环

Php 使用正则表达式永不结束do-while循环,php,regex,do-while,pcre,regex-lookarounds,Php,Regex,Do While,Pcre,Regex Lookarounds,我试图在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 "sau

我试图在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>
例如,我有一个带有图案的数组:

        $patterns[1] = array(
            'find' => "/[«‹]\K(?!\x{00A0})\s/imu",
            'repl' => "&#8239;"
            );
        $patterns[2] = array(
            'find' => "/[«‹]\K(?!\p{Zs})/imu",
            'repl' => "&#8239;"
            );
图案1应与上述trans unit 1匹配,图案2应与trans unit 2匹配。模式1工作得很好,但如果我运行模式2(仅运行模式2或同时运行模式2),循环将永远不会结束。替换基本上是将«或è之后的正常(断开)空间(模式1)替换为狭窄的断开空间,或者在完全没有空间的情况下插入它(模式1)


我会说这个问题与第二个正则表达式有关,但我不知道这个表达式有什么问题。任何提示?

\p{Zs}
模式与
 不匹配,因此添加
到第二个模式中的先行条件:

'find' => "/[«‹]\K(?!\p{Zs}|&#8239;)/iu",) 
                            ^^^^^^^           

有时人们会在问题中添加样本数据……对不起,我认为这与问题无关。现在添加,谢谢!与这个问题无关,但它是用法语写的,我做了一个非常错误的假设:我的模式
\p{Zs}
会匹配
&,但事实并非如此。将“ ;”添加到muy模式2(即,
'find'=>”/[«è]\K(?!\p{Zs}) ;)/imu“,
)似乎解决了这个问题。谢谢。我不能发布答案,因此我不能投票认为问题已经解决。没错,正如我在11月17日的评论中所发布的。Thans,Wiktor:)
'find' => "/[«‹]\K(?!\p{Zs}|&#8239;)/iu",) 
                            ^^^^^^^