首页 > 解决方案 > 这是关于 Notepad++ 正则表达式替换

问题描述

我想换

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

代码行到

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

在 NotePad++ 中,但我不能写出完全正确的正则表达式。请帮帮我。

标签: notepad++

解决方案


  • Ctrl+H
  • 找什么:<th scope="col">\K@translate\((.+?)\)(?=</th>)
  • 用。。。来代替:{{trans("file.$1")}}
  • 检查 火柴盒
  • 检查 环绕
  • CHECK 正则表达式
  • Replace all

解释:

<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

截图(之前):

在此处输入图像描述

截图(之后):

在此处输入图像描述


推荐阅读