随笔 - 74  文章 - 0  评论 - 94  阅读 - 12万

EmEditor的一个好用的正则替换功能

最近在编辑文本的时候用到了EmEditor的一个好用的正则替换功能。
即我想用搜索到内容的一部分来生成另一段文本。
例如客户提供给我一大堆MYSQL的建立主键的脚本,我想改成MSSQL的建立主键的脚本,这里就用到了这个功能。

复制代码
--替换前:
ALTER TABLE  XXXX
ADD PRIMARY KEY PK_XXXX
(
 ID ASC
);
--替换后
ALTER TABLE XXXX
ADD CONSTRAINT PK_XXXX PRIMARY KEY CLUSTERED
(
 ID ASC
);
--当然直接删掉PK_XXXX也能符合MSSQL的语法,这里仅为了举例子.
复制代码

这里可以使用
查找:
ADD PRIMARY KEY (.*)
替换为:
ADD CONSTRAINT \1 PRIMARY KEY CLUSTERED
具体规则可以参考EmEditor的正则表达式帮助文档:\1 - \9
Indicates a back reference - a back reference is a reference to a previous sub-expression that has already been matched. The reference is to what the sub-expression matched, not to the expression itself. A back reference consists of the escape character "\" followed by a digit "1" to "9", "\1" refers to the first sub-expression, "\2" to the second etc. For example, "(a)\1" would capture "a" as the first back reference and match any text "aa". Back references can also be used when using the Replace feature under the Search menu. Use regular expressions to locate a text pattern, and the matching text can be replaced by a specified back reference. For example, "(h)(e)" will find "he", and putting "\1" in the Replace With box will replace "he" with "h" whereas "\2\1" will replace "he" with "eh".

posted on   万剑齐发  阅读(750)  评论(0编辑  收藏  举报
编辑推荐:
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示