这是关于 Notepad++ 正则表达式替换

问题描述

我想换

<th scope="col">@translate(Product)</th> 

代码

<th scope="col">{{trans("file.Product")}}</th> 

在 NotePad++ 中,但我无法编写完全正确的正则表达式。 请帮帮我。

解决方法

  • Ctrl+H
  • 查找内容:<th scope="col">\K@translate\((.+?)\)(?=</th>)
  • 替换为:{{trans("file.$1")}}
  • 检查 匹配案例
  • 检查 环绕
  • 检查 正则表达式
  • 全部替换

说明:

<th scope="col">        # literally
\K                      # forget all we have seen until this position
@translate              # literally
\(                      # openning parenthesis
(.+?)                   # group 1,1 or more any character,not greedy
\)                      # closing parenthesis
(?=</th>)               # positive lookahead,make sure we have a closing tag after

屏幕截图(之前):

enter image description here

屏幕截图(之后):

enter image description here