PHP 正则表达式与贪婪的问题


PHP regex problems with greediness

我正在尝试删除所有看起来像这样的html:

<p><font face="Arial" size="2"><a href="#top">Back to the top</a></font></p>

字体和大小各不相同,可能还有其他一些东西。

为了确保,我使用以下正则表达式:

/<p.*?><font.*?><a href=.*?>Back.*?<'/a><'/font><'/p>/is

但是,它与我正在搜索的完整文本字符串匹配,例如:

<p>However, if this is our reaction, we will indeed be weak in our weaknesses. For the strength of Christ does not come to rest upon us in the midst of discontent and rebellion.</p> <p>Seeing the great design of the Lord in affliction, let us rather take pleasure in our afflictions. Let us glory, that is boast, in them, and in wisdom let us then turn to Jesus Christ our Savior to receive His great strength.</p> <p>Then in our weakness we will be indeed very strong!</p> <p><font face="Arial" size="2"><a href="#top">Back to the top</a></font></p> <hr> 

我做错了什么?!?

将点更改为 [^>]

/<p[^>]*?><font[^>]*?><a href=[^>]*?>Back[^>]*?<'/a><'/font><'/p>/is