Regex 使用两个通配符查找正则表达式,替换其中一个-TextMate

Regex 使用两个通配符查找正则表达式,替换其中一个-TextMate,regex,textmate,Regex,Textmate,我需要在几十个不同的html文档中查找和替换数千个目标URL(AHREF)。。。所有AHREF的格式都不同。我需要用一个统一的目标url替换所有不同的目标url 有两个障碍: 我不想把css文件引用的linkhrefs搞砸,而是只想更改实际的ahrefs 2.在这些文件中,AHREF没有统一的结构。有些在a和href之间有class=stuff。例子包括: <a class='image' href="examplelinkone.com"> <a class='image

我需要在几十个不同的html文档中查找和替换数千个目标URL(AHREF)。。。所有AHREF的格式都不同。我需要用一个统一的目标url替换所有不同的目标url

有两个障碍:

  • 我不想把css文件引用的linkhrefs搞砸,而是只想更改实际的ahrefs
  • 2.在这些文件中,AHREF没有统一的结构。有些在a和href之间有class=stuff。例子包括:

     <a class='image' href="examplelinkone.com">
    <a class='image ' href="examplelinkone.com"> ( space between e and ' )
    <a class='someotherclass' href="examplelinktwo.com"
    
    
    (e和''之间的空格)
    
    您需要使用捕获组

    (<a[^<>]+href=")[^<>]+(")
    

    $1
    表示我们重新引用组索引1中存在的字符(
    类似于此模式的内容应该可以消除
    href=
    的引号之间的任何内容:

    \b(href=\W)[\w\s.]+(?=\W)\b
    
    替换为:

    $1
    
    -在TextMate中测试:

     <a class="image" href="examplelinkone.com">anything<a href="more">
    <a class='image ' href='examplelinkone.com'> ( space between e and ' )"<something>"All ok"</a>
    <a class='someotherclass' href="examplelinktwo.com"
    
    
    
    这就是为什么不将HTML与正则表达式匹配。想象一下:
    。某些语言或工具使用
    \1
    而不是
    $1
    $1
    
     <a class="image" href="examplelinkone.com">anything<a href="more">
    <a class='image ' href='examplelinkone.com'> ( space between e and ' )"<something>"All ok"</a>
    <a class='someotherclass' href="examplelinktwo.com"
    
     <a class="image" href="">anything<a href="">
    <a class='image ' href=''> ( space between e and ' )"<something>"All ok"</a>
    <a class='someotherclass' href=""