如何根据当前行的第一个字符从上一行中删除换行符?

时间:2012-08-28 00:19:13

标签: regex notepad++

我以CSV格式导出了一些数据,这些数据在文本字段中有一些换行符。我无法让Excel正确处理这个问题。我想编辑文件以删除这些换行符。

有效记录以数字开头。我已经尝试将\ n ^([^ \ d])放入Notepad ++ find / replace的Find what框中,以匹配以非数字和前一个换行符开头的任何行。它匹配正确。在替换为框中,我放置一个空格,后跟\ 1,用空格替换换行符并保留匹配的字符。但是,替换根本不起作用,没有任何改变。

我做错了什么?

示例文字:

123,0,1,"This is a single line comment","bob","jim"
124,0,1,"This is a multi line comment w/ newline.
This is the second line of the comment","ted","alfred"
125,0,1,"This is another single line comment","jim","bob"

我想在“这是第二个......”之前用空格替换换行符,以便文件看起来像这样:

123,0,1,"This is a single line comment","bob","jim"
124,0,1,"This is a multi line comment w/ newline. This is the second line of the comment","ted","alfred"
125,0,1,"This is another single line comment","jim","bob"

2 个答案:

答案 0 :(得分:1)

想出来。我使用(\ n)^(?!\ d +,\ d +)来匹配任何换行符,后跟一行后面没有后跟至少一个数字,一个逗号和至少一个数字的行。替换我只是放了一个空格。

答案 1 :(得分:-1)

如果将换行符设置为Unix(LF),则

\ n在Notepad ++中有效。 如果在Windows(CR LF)中,则\ r \ n应该可以运行,或者将返回值转换为Unix(底部栏)