簡體   English   中英

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM