Regex 正则表达式查找并用特定类替换锚点的扩展

Regex 正则表达式查找并用特定类替换锚点的扩展,regex,notepad++,Regex,Notepad++,我有一个项目,我需要翻译的网址从维基空间格式到wordpress。我要找的是替换 .html 与 / 其中文本采用以下格式 <a class="identifier-class" href="<some_variable_url>.html>......</a> 与 我可以用什么字符串替换正则表达式来替换记事本+++首先,您应该始终显示您迄今为止尝试过的内容。 其次,答案是: 在中查找您放置的内容: a class="identifier-clas

我有一个项目,我需要翻译的网址从维基空间格式到wordpress。我要找的是替换

.html

/

其中文本采用以下格式

<a class="identifier-class" href="<some_variable_url>.html>......</a> 



我可以用什么字符串替换正则表达式来替换记事本+++

首先,您应该始终显示您迄今为止尝试过的内容。 其次,答案是:

中查找您放置的内容:

a class="identifier-class" href="([^"]*?)\.html*?"
()中包含的内容表示捕获此字符串。这是你需要的绳子。这就是我在外部添加.html的原因。您看到
\.html
而不是
.html
的原因是。(点)是正则表达式模式中的一个特殊字符,需要转义才能像简单的点一样处理

替换为中,您可以这样写:

a class="identifier-class" href="$1/"
$1在本例中是()中捕获的字符串(请参见上面的说明)

我在以下字符串上进行了测试(请注意,还有一个链接与另一个标识符类(而不是我)链接,该链接将被跳过)


这就是工作:

  • Ctrl+H

  • 查找内容:
    如果一行中有多个
    href=“…”
    ,则此操作无效。@Toto我不知道您尝试了什么,但它确实有效。我刚刚测试过。例如在一个字符串上:
    @Toto您是对的,谢谢!我错过了两次:第一次考试,第二次考试——当你第一次指出的时候。对不起。。。我更正了答案。@Besciulex我有多个锚定标记,我只需要替换锚定包含标识符类的位置。我有多个锚定标记,我只需要替换锚定包含标识符类的位置。
    a class="identifier-class" href="$1/"
    
    <a class="identifier-class" href="/some_variable_url/cucu.html"/>......</a> <a class="identifier-class" href="/anotehr_variable_url/mucu.html"/>......</a> 
    <a class="another-identifier-class-not-me" href="/some_variable_url/cucu.html"/>......</a>
    <a class="identifier-class" href="/anotehr_variable_url/mucu.html"/>......</a> <a class="identifier-class" href="/some_variable_url/cucu.html"/>......</a>
    <a class="identifier-class" href="/anotehr_variable_url/mucu.html"/>......</a> 
    
    <a class="identifier-class"  : literally
    href="[^"]+ : search for href=", followed by 1 or more any character that is not double quote "
    \K          : forget all we have seen until this position
    \.html      : literally ".html"
    (?=")       : lookahead, make sure we have '"' after