简体   繁体   English

正则表达式,排除 html 中的文件名

[英]Regex, exclude filename in html

Html Code 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>

I want to exclude <img> tag that has "stars.png", enclosed by <a> tag.我想排除带有“stars.png”的<img>标签,由<a>标签包围。

My regex:我的正则表达式:

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

It doesn't work.它不起作用。 This picks up nothing.这什么都没有。 Correct match should only pickup 2nd <a> tag with <img> that has "images/thx/kek.png" but not "images/thx/star.png".正确的匹配应该只拾取带有“images/thx/kek.png”而不是“images/thx/star.png”的<img>第二个<a>标签。

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

^ and $ match the start and the end of the line, and they are likely not what you want to match, so I remove them. ^$匹配行的开头和结尾,它们可能不是您想要匹配的内容,因此我将它们删除。 [^>]* matches all the content in img tag and stops just before the closing > . [^>]*匹配img标签中的所有内容,并在结束>之前停止。 Lookahead assertion (?!.*star\\.png) after it starts matching from that > and not the content in img tag, so I move it in front of [^>]* .前瞻断言(?!.*star\\.png)从那个>而不是img标签中的内容开始匹配,所以我将它移到[^>]*前面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM