【问题标题】:Double line breaks with Notepadd++Notepad++ 的双换行符
【发布时间】:2015-07-30 15:07:07
【问题描述】:

我正在准备一些 Whatsapp 聊天日志,用于渲染统计数据和 wordcloud。然而,我的数据时不时地有双换行符,这与日志的格式相混淆,我想知道如何自动修复。

13 Mar 18:51 - nicola: mainly he's crap
13 Mar 18:52 - Sebastian K: ... you didn't really dress it up
13 Mar 18:52 - nicola: and he has no natural grace like most cats 

well no i didn't lol
13 Mar 18:52 - nicola: you saw the last video
13 Mar 18:53 - Sebastian K: Stilton jumped onto that wall effortlessly while Ched almost killed himself yea...

搜索并删除空行(容易修复)。但是,我仍然留下破坏日期和时间格式的行:

13 Mar 18:51 - nicola: mainly he's crap
13 Mar 18:52 - Sebastian K: ... you didn't really dress it up
13 Mar 18:52 - nicola: and he has no natural grace like most cats 
well no i didn't lol
13 Mar 18:52 - nicola: you saw the last video
13 Mar 18:53 - Sebastian K: Stilton jumped onto that wall effortlessly while Ched almost killed himself yea...

目标格式:

13 Mar 18:51 - nicola: mainly he's crap
13 Mar 18:52 - Sebastian K: ... you didn't really dress it up
13 Mar 18:52 - nicola: and he has no natural grace like most cats well no i didn't lol
13 Mar 18:52 - nicola: you saw the last video
13 Mar 18:53 - Sebastian K: Stilton jumped onto that wall effortlessly while Ched almost killed himself yea...

也许解决方案是利用此规则:我需要保留以下模式的换行符:

TEXT *linebreak* 
NUMBER(begging of date column)

讨厌的遵循模式:

TEXT *linebreak*
TEXT

如何使用 Notepad++ 修复它?

【问题讨论】:

    标签: regex replace notepad++ line-breaks


    【解决方案1】:

    在搜索和替换对话框中,您可以搜索此模式

    \r\n(?!\d)
    

    启用正则表达式并替换为空。

    \r\n 搜索由 CR 和 LF 组成的换行符。在 Notepad++ 中启用控制字符的显示以查看您有哪些换行符。

    (?!\d)negative lookahead 断言是真的,当没有数字跟随时。这适用于您的示例,但在某些极端情况下可能会失败,您可以将其扩展到模式,例如(?!\d{2}\s) 当日期始终为两位数时。

    【讨论】:

      猜你喜欢
      • 2021-03-21
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多