簡體   English   中英

正則表達式,排除 html 中的文件名

[英]Regex, exclude filename in html

html代碼

<div class="thx_thanked_post"><a title="Click to enlarge" target="_blank" data-fancybox="data-2581" data-type="image" href="images/thx/star.png"><img src="images/thx/star.png" alt="Better response on post dqwdqwdqwqdwdqwqwdwdwd" class="thx_thanked_post_img"></a>Just a "quick" overview of what's good and why.<br>

<a title="Click to enlarge" target="_blank" data-fancybox="data-2581" data-type="image" href="images/thx/kek.png"><img src="images/thx/kek.png" alt="Better response on post dqwdqwdqwqdwdqwqwdwdwd" class="thx_thanked_post_img"></a>
<br>
Note: Hyper speed is referenced multiple times here. This is a bug(?) where after reaching speeds over 160 km/h, you continue accelerating like crazy while traveling in a straight line, allowing you to reach speeds of over 500 km/h with a good boost under ideal conditions. Making good use of hyper speed when possible is huge for cutting time, and much of what makes something good is how easily and consistently it works to give hyper speed.<br>

我想排除帶有“stars.png”的<img>標簽,由<a>標簽包圍。

我的正則表達式:

<a [^>]*\>([\t]|[\n])*<img[^>]*^(?!.*star\.png$)[^>]*\>([\t]|[\n])*<\/a>

它不起作用。 這什么都沒有。 正確的匹配應該只拾取帶有“images/thx/kek.png”而不是“images/thx/star.png”的<img>第二個<a>標簽。

<a [^>]*>([\\t]|[\\n])*<img(?!.*star\\.png)[^>]*>([\\t]|[\\n])*<\\/a>似乎有效。

^$匹配行的開頭和結尾,它們可能不是您想要匹配的內容,因此我將它們刪除。 [^>]*匹配img標簽中的所有內容,並在結束>之前停止。 前瞻斷言(?!.*star\\.png)從那個>而不是img標簽中的內容開始匹配,所以我將它移到[^>]*前面。

暫無
暫無

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

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