Notepad++高级查找替换:为send行添加对应ex编号注释
在Notepad++中批量添加对应编号的说明行
原始文档内容
ex 1 send power g1 g2 g3 g4 ex 2 send power g1 g2 ex 3 send power g1 f5 f3 ex 4 send f5 f2 t5
目标效果
ex 1 send power g1 g2 g3 g4 this is number `1' ex 2 send power g1 g2 this is number `2' ex 3 send power g1 f5 f3 this is number `3' ex 4 send f5 f2 t5 this is number `4'
实现步骤
- 打开Notepad++并加载目标文档。
- 按下快捷键
Ctrl+H打开替换窗口(也可通过菜单栏「搜索」→「替换」打开)。 - 在窗口左下角「搜索模式」中选择「正则表达式」。
- 在「查找内容」输入框粘贴以下正则表达式:
(ex (\d+)\r?\n)(send.*?)\r?\n - 在「替换为」输入框粘贴以下内容:
$1$3\r\nthis is number `$2' \r\n - 点击「全部替换」按钮,即可完成批量修改。
正则逻辑说明
(ex (\d+)\r?\n):捕获以ex开头的行,其中(\d+)提取出编号数字,\r?\n兼容Windows(\r\n)和Unix(\n)的换行格式。(send.*?)\r?\n:捕获以send开头的行,.*?非贪婪匹配行内内容,避免跨多行匹配。- 替换内容里的
$1对应捕获的ex行,$3对应捕获的send行,$2对应提取出的编号数字,以此实现对应编号的说明行插入。
内容的提问来源于stack exchange,提问作者a_todd12
相关产品推荐
相关产品推荐

