如何使用正则表达式删除两行之间的空格? [英] How to use regex to remove the spaces between two rows?

查看:234
本文介绍了如何使用正则表达式删除两行之间的空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的输入文件是这样的

Header1,,,,,,,,,,,
c1 , c2 , c3 ,,,,

 22-02-2017,1-2,10,,,,
 22-02-2017,2-3,11,,,,

 22-02-2017,4-6,10,,,,
 22-02-2017,5-8,11,,,,

我需要进行正则表达式以使其达到预期的输出以下:

I need to regex to achive below expected output:

Header1,,,,,,,,,,,
c1 , c2 , c3 ,,,,
22-02-2017,1-2,10,,,,
22-02-2017,2-3,11,,,,
22-02-2017,4-6,10,,,,
22-02-2017,5-8,11,,,,

我尝试使用此正则表达式在REplaceTExt中搜索\ s \ n,替换值为\ n.

I trying this regex for search \s\n in REplaceTExt and replacement value is \n.

替换如下所示的文本输出内容之后,

After Replace text output content like below.,

Header1,,,,,,,,,,,c1 , c2 , c3 ,,,,22-02-2017,1-2,10,,,,22-02-2017,2-3,11,,,,22-02-2017,4-6,10,,,,

但是我的正则表达式在regexr网站上运行得很好.

But my regex worked perfectly in regexr website.

http://regexr.com/3fbse

还有其他正则表达式来搜索空行并合并空行之前和之后的行吗?

Is there is any other regex to search empty rows and combine rows before and after of empty rows?

推荐答案

搜索:\n\n\s|\n\s

替换:\n

Regex演示

这篇关于如何使用正则表达式删除两行之间的空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆