正则表达式:查找仅突出显示一个单词的链接

正则表达式:查找仅突出显示一个单词的链接

我有这两个链接,一个突出显示一个单词game,另一个突出显示单词,acapulco heat

  1. <a href="https://mywebsite.com/page-one.html" class="color-bebe" target="_new">game</a>

  2. <a href="https://mywebsite.com/page-one.html" class="color-bebe" target="_new">acapulco heat</a>

我想使用正则表达式来查找仅突出显示一个单词的链接,例如第一行。

输出应为:

<a href="https://mywebsite.com/page-one.html" class="color-bebe" target="_new">game</a>

或简单:

game

答案1

  • Ctrl+F
  • 找什么:<a [^>]*"color-bebe".*?>\K\w+(?=</a>)
  • 查看 环绕
  • 查看 正则表达式
  • Find next

解释:

<a                  # start a tag
[^>]*               # 0 or more any character that is not >
"color-bebe"        # literally
.*?                 # 0 or more any character, not greedy
>                   # >
\K                  # forget all we have seen until this position
\w+                 # 1 or more word character, you can use \S (non space characters)
(?=</a>)            # positive lookahead, make sure we have the close tag

截屏:

在此处输入图片描述

答案2

  • 找什么:<a.+>(\w+)</a>
  • 搜索模式:正则表达式。

可选替换为:$1

相关内容