如何在 notepad++ 中连接行与行之间的空格

如何在 notepad++ 中连接行与行之间的空格

有没有办法在新行之间连接行(返回),并保留新行(返回)?选择新行之间的文本后使用Ctrl+执行此操作,但对于大型文档不实用。J

可以将文本转换为:

Mary had a 
little lamb.
His fleece was 
white as snow, yeah.

And everywhere 
the child went.
That little lamb 
was sure to go now.

He followed her 
to school one day.
Which broke the 
teachers cool.

到:

Mary had a little lamb. His fleece was white as snow, yeah.
    
And everywhere the child went. That little lamb was sure to go now.
    
He followed her to school one day. Which broke the teachers cool.

答案1

  • Ctrl+H
  • 找什么:(?<!\r\n)\r\n(?!\r\n)
  • 替换为:无(空字符串)
  • 搜索模式:正则表达式

然后全部替换

(?<!\r\n)(?!\r\n)是正则表达式查找,以确保只匹配 1 个新行。如果文件是 Unix 格式,则只需删除\r


如果你还想在标点符号后添加空格,那么使用这个

  • Ctrl+H
  • 找什么:([[:punct:]])(?=\R\S)
  • 替换为:(\1末尾有一个空格)
  • 搜索模式:正则表达式
  • 全部替换,然后执行(?<!\r\n)\r\n(?!\r\n)上述替换

答案2

  • CTRL+H
  • 找什么:(.+)\R(.+)\R(.+)\R(.+\R?)
  • 用。。。来代替:$1$2$3$4
  • 搜索模式:正则表达式
  • 单击“全部替换”

单击“全部替换”之前输入

单击“全部替换”后的输出

相关内容