You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何用Notepad正则表达式替换文本,交换中间表达式两侧内容位置?

Notepad++ 正则调换固定表达式两侧内容方案

需求说明

原始文本:

into this ($$) business if not to ($$) save the world

目标文本:

save the world ($$) business if not to ($$) into this

需要将($$) business if not to ($$)两侧的内容互换位置。

操作步骤

  1. 打开Notepad++,加载目标文本。
  2. 按下Ctrl+H打开替换窗口。
  3. 勾选「正则表达式」模式(无需勾选「匹配换行符」)。
  4. 在「查找内容」中输入正则匹配规则:
    ^(.*?) \(\$\$\) business if not to \(\$\$\) (.*)$
    
    • ^(.*?):非贪婪捕获开头到第一个 ($$)前的所有内容(对应示例中的into this)
    • \(\$\$\) business if not to \(\$\$\):精确匹配中间固定文本,(、)、$是正则特殊字符,必须用\转义
    • (.*)$:捕获最后一个 ($$)到文本结尾的所有内容(对应示例中的save the world)
  5. 在「替换为」中输入替换规则:
    \2 \(\$\$\) business if not to \(\$\$\) \1
    
    • \2:调用第二个捕获组的内容(原文本后半段的save the world)
    • \1:调用第一个捕获组的内容(原文本前半段的into this)
  6. 点击「全部替换」完成内容调换。

内容的提问来源于stack exchange,提问作者raghsak

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 19:47:11