简体   繁体   English

Notepad ++ html标记/字符串(a href)替换

[英]Notepad++ html tag / string (a href) replace

I found another post that uses the following regex <a[^>]*>([^<]+)</a> it works great however I want to use a capture group to target URLs that have the following 4 letters in them RTRD . 我发现另一篇使用以下正则表达式<a[^>]*>([^<]+)</a> [^> <a[^>]*>([^<]+)</a>帖子效果很好,但是我想使用捕获组来定位其中包含以下4个字母的URL RTRD

I used <a[^>]*>(RTRD+)</a> and that did not work. 我使用<a[^>]*>(RTRD+)</a> ,但是没有用。

<a href="http:\\\\something.RTRD.html">TESTER</a> I want to remove the URL and leave TESTER <a href="http:\\\\something.RTRD.html">TESTER</a>我要删除URL并保留TESTER

<a href="http:\\\\something.RTRB.html">LEAVE</a> I want to not touch this one. <a href="http:\\\\something.RTRB.html">LEAVE</a>我不想碰这一个。

One that will work: <a\\s[^>]*href\\=[\\"][^\\"]*(RTRD)[^\\"]*[\\"][^>]*>([^<]+)<\\/a> 会起作用的一个: <a\\s[^>]*href\\=[\\"][^\\"]*(RTRD)[^\\"]*[\\"][^>]*>([^<]+)<\\/a>

Decomposition: 分解:

<a\\s[^>]* find opening a tag with space followed by some arguments <a\\s[^>]*发现使用空格后跟一些参数来打开标签

href\\=[\\"][^\\"]* find href attribute with " opening and then multiple non " closing href\\=[\\"][^\\"]*查找带有“开头,然后是多个非”结尾的href属性

(RTRD) Your Key group (RTRD)您的密钥组

[^\\"]*[\\"] Find remainder of argument and closing " [^\\"]*[\\"]查找参数的其余部分并关闭“

[^>]*>([^<]+)<\\/a> The remainder of the original regex [^>]*>([^<]+)<\\/a>原始正则表达式的其余部分


Things your original RegExp would match: <a stuffhere!!.,?>RTRDDD</a> <a>RTRD</a> 您原来的RegExp可以匹配的内容: <a stuffhere!!.,?>RTRDDD</a> <a>RTRD</a>

Decomposing your RegExp: 分解您的RegExp:

<a[^>]*> Look for opening tag with any properties <a[^>]*> [^> <a[^>]*>查找具有任何属性的开始标记

(RTRD+) Look for the RTRD group but also match one or more D (RTRD+)查找RTRD组,但还要匹配一个或多个D

<a[^>]*> Look for closing tag <a[^>]*> [^> <a[^>]*>查找结束标记

Use <a[^>]*RTRD[^>]*>([^<]+)<\\/a> here. <a[^>]*RTRD[^>]*>([^<]+)<\\/a>

Inside the opening tag ( <a[^>]*> ) should be the pattern RTRD somewhere. 在开始标签( RTRD <a[^>]*> )内应该是RTRD模式。 This can be done by replacing [^>]* with [^>]*RTRB[^>]* which is simply 这可以通过用[^>]* [^>]*RTRB[^>]*替换[^>]*来完成,这很简单

  • [^>]* Anything thats not a > (closing tag) [^>]*并非> (结束标记)的内容
  • RTRB The pattern RTRB RTRB模式RTRB
  • [^>]* Again anything thats not a > [^>]*再次是不是>

But caution: This also matches <aRTRB>test</a> or <a id="RTRB">blubb</a> 但请注意:这也匹配<aRTRB>test</a><a id="RTRB">blubb</a>

And if you have any other way than using Regex on HTML, use that way (string operations etc) 并且,如果您除了在HTML上使用Regex之外,还有其他方法,请使用该方法(字符串操作等)

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

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