Notepad++ - 将 SQL Server 中的大查询变成一行

SaC*_*CvP 2 notepad++ string-formatting

我在 notepad++ 中从 SQL Server 有一个大查询(1012 行),并且我想将此查询仅传递到一行。例如,我有这个:

SELECT *
FROM tableA
WHERE Field_A = 1
Run Code Online (Sandbox Code Playgroud)

我想讲一下:

SELECT * FROM tableA WHERE Field_A = 1
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用以下代码:

  1. 打开替换对话框(Ctrl + H)
  2. 检查环绕选项
  3. 选择正则表达式搜索模式
  4. (\h*\R)+在“查找内容:”区域中填写正则表达式
  5. \x20在替换为:区域中填写正则表达式
  6. 单击全部替换按钮

但它给我创建了更多新行,代码之间有很大的空间。

我怎样才能做到这一点?

Tot*_*oto 10

您必须删除换行符后的空格,使用此正则表达式(?:\h*\R\h*)+

  • Ctrl+H
  • 找什么:(?:\h*\R\h*)+
  • 用。。。来代替:A SINGLE SPACE
  • 检查环绕
  • 检查正则表达式
  • Replace all

解释:

(?:         : start non capture group
    \h*     : 0 or more horizontal spaces
    \R      : any kind of linebreak (ie. \r, \n, \r\n)
    \h*     : 0 or more horizontal spaces
)+          : end group, repeated 1 or more times
Run Code Online (Sandbox Code Playgroud)

替代品:

A single space
Run Code Online (Sandbox Code Playgroud)

给出的例子如下:

SELECT *

            FROM tableA



WHERE Field_A = 1
Run Code Online (Sandbox Code Playgroud)

给定示例的结果:

SELECT * FROM tableA WHERE Field_A = 1 
Run Code Online (Sandbox Code Playgroud)