Notepad++ 记事本++;-将SQL Server中的大查询转换为一行
我在notepad++中有一个来自SQL Server的大查询(1012行),我只想将此查询传递到一行。例如,我有一个:Notepad++ 记事本++;-将SQL Server中的大查询转换为一行,notepad++,string-formatting,Notepad++,String Formatting,我在notepad++中有一个来自SQL Server的大查询(1012行),我只想将此查询传递到一行。例如,我有一个: SELECT * FROM tableA WHERE Field_A = 1 我想说的是: SELECT * FROM tableA WHERE Field_A = 1 我正在使用以下代码进行尝试: 打开“替换”对话框(Ctrl+H) 选中环绕选项 选择正则表达式搜索模式 在查找内容:区域中填写正则表达式(\h*\R)+ 在替换为:区域中填写regex\x20 单击“全部
SELECT *
FROM tableA
WHERE Field_A = 1
我想说的是:
SELECT * FROM tableA WHERE Field_A = 1
我正在使用以下代码进行尝试:
(\h*\R)+
\x20
如何执行此操作?您应该能够用一个空格替换行结尾的
\r\n
。请注意,我将\r
设置为可选,以防您可能在Linux上,其中行尾只是\n
查找:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
替换:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
这将确保前一行的末尾和当前行的开头之间至少有一个空格。额外的空白不应导致SQL查询被错误地解析。您应该能够用一个空格替换
\r\n
,行的结尾。请注意,我将\r
设置为可选,以防您可能在Linux上,其中行尾只是\n
1. Open the Replace dialog ( Ctrl + H )
2. Check the Wrap around option
3. Choose the Extended search mode
4. Fill in the regex \r\n in the Find what: zone
5. Put one white space in the Replace with: zone
6. Click on the Replace All button
查找:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
替换:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
这将确保前一行的末尾和当前行的开头之间至少有一个空格。额外的空白不应导致SQL查询被错误解析
1. Open the Replace dialog ( Ctrl + H )
2. Check the Wrap around option
3. Choose the Extended search mode
4. Fill in the regex \r\n in the Find what: zone
5. Put one white space in the Replace with: zone
6. Click on the Replace All button
根据您的换行习惯,第4步。可以是:
4bis. Fill in the regex \n in the Find what: zone
可以使用以下选项显示换行符:
查看->显示符号->显示行尾
。
如果显示CRLF
,执行步骤4将回答您的问题。如果看到LF
,则需要执行步骤4bis
正如Tim Biegeleisen所建议的,您还可以使用正则表达式搜索模式(步骤3)并填写regex\r?\n
。这两种方法同时起作用
根据您的换行习惯,第4步。可以是:
4bis. Fill in the regex \n in the Find what: zone
可以使用以下选项显示换行符:
查看->显示符号->显示行尾
。
如果显示CRLF
,执行步骤4将回答您的问题。如果看到LF
,则需要执行步骤4bis
正如Tim Biegeleisen所建议的,您还可以使用正则表达式搜索模式(步骤3)并填写regex
\r?\n
。这将同时执行这两项操作。您必须在换行符之后删除空格,请使用此正则表达式(?:\h*\R\h*)+
- Ctrl+H
- 查找内容:
(?:\h*\R\h*)+
- 替换为:
单个空格
- 检查环绕
- 检查正则表达式
- 全部替换
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
更换:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
给出的示例如下:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
给定示例的结果:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
您必须在换行符之后删除空格,请使用此正则表达式
(?:\h*\R\h*)+
- Ctrl+H
- 查找内容:
(?:\h*\R\h*)+
- 替换为:
单个空格
- 检查环绕
- 检查正则表达式
- 全部替换
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
更换:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
给出的示例如下:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
给定示例的结果:
\r?\n
[single space]
(?: : 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
A single space
SELECT *
FROM tableA
WHERE Field_A = 1
SELECT * FROM tableA WHERE Field_A = 1
你试过CTRL+A然后CTRL+J吗?CTRL+J已经添加了一个空格,所以您不必担心会破坏SQL查询。@Andrea:这不会删除额外的空格。您尝试过CTRL+a然后CTRL+J吗?CTRL+J已经添加了一个空格,所以您不必担心会破坏SQL查询。@Andrea:这不会删除额外的空格。