仅在引号括起时才移除换行符 [英] Remove line breaks only if surrounded by quotes

查看:254
本文介绍了仅在引号括起时才移除换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文本文件中有大量的数据,给我一些问题。文件中的许多记录在记录之间有换行符。例如,这是我目前的数据:

I have a large amount of data in a text file that has been giving me some issues. A lot of the records in the file have line breaks in between the record. For example this is what my data looks like currently:

30670169,           Corvette,   EL-P078675,     EL-P078675, Chevrolet  Corvette C6 Color Matching Millenium Yellow License Plate Frame,     "Made from high-quality billet aluminum, this stylish license frame is custom painted to precisely match the color of your C6 Corvette.

It features an engraved OEM style nameplate. High-gloss finished will never rust.

12"" x 6"" in standard size. Includes color matched screw covers and hardware.

This is a special custom made item. It takes 10-15 business days to ship.

Brand new official licensed product."

这应该是这样读的:

30670169,           Corvette,   EL-P078675,     EL-P078675, Chevrolet  Corvette C6 Color Matching Millenium Yellow License Plate Frame,     "Made from high-quality billet aluminum, this stylish license frame is custom painted to precisely match the color of your C6 Corvette. It features an engraved OEM style nameplate. High-gloss finished will never rust. 12"" x 6"" in standard size. Includes color matched screw covers and hardware. This is a special custom made item. It takes 10-15 business days to ship. Brand new official licensed product."

我需要一种方法来删除换行符,如果它们被引号包围。

I need a method to delete line breaks ONLY if they are surrounded by quotes. Anyone have any ideas?

推荐答案

尝试使用Notepad ++的查找/替换功能。

Try using the Find/Replace function of Notepad++.

查找:

\r(?!\n)

替换为 (空格)

您需要检查正则表达式复选框:

You will need to check the regular expression checkbox:

尝试首先替换几行(例如选择前80行),然后在选择中替换即可看到。

Try replacing in a few lines first (select the first 80 lines for example) and then replace in selection just to see. If that works, you can proceed with the whole file.

在上面的 \r 中会匹配一个CR和 \\\
将匹配LF。 (?! \\\
是一个特殊组,表示不匹配 \r \ n '。

In the above \r will match a CR and \n will match an LF. (?!\n) is a special group that means 'don't match \r if it is followed by \n'.

注意:我认为notepad ++有时不能正确替换,因此,如果立即替换整个文件会导致问题,请尝试替换较小的批次。

Note: I think that notepad++ sometimes doesn't do the replace correctly, so if replacing the whole file at once cause issues, try replacing in smaller batches.

我通常使用脚本做这样的事情,但我不认为你' d如果你不熟悉,可以使用脚本:

I usually use a script to do something like this but I don't think you'd be ready to use a script if you're not used to it :s

这篇关于仅在引号括起时才移除换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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