Notepad++ 合并所有不以日期开头的行

Notepad++ 合并所有不以日期开头的行

.csv在 Notepad++ 中有一个文件,其中包含如下数据:

1-6-2018,"(101)","","Sale",-862.96,,
"(Sale)",,837.96,
,"Diesel",12.000 Ltr,69.83/Ltr,837.96,
"Sales @ 5%",,23.80,
,"Polishing Cloth",1 Pcs,23.80/Pcs,23.80,
"CGST @ 2.5%",,0.60,
"SGST @ 2.5%",,0.60,
"(No. :16532)",
1-6-2018,"(149)","","Sale",-3212.18,,
"Sales(Sale)",,3212.18,
,"Diesel",46.000 Ltr,69.83/Ltr,3212.18,
"(No. :16533)",
// and many more

如何在 Notepad++ 中使用搜索和替换(或任何其他方法)来合并所有不以日期开头的行,以便最终结果看起来像这样?

1-6-2018,"(101)","","Sale",-862.96,,"(Sale)",,837.96,,"Diesel",12.000 Ltr,69.83/Ltr,837.96,"Sales @ 5%",,23.80,,"Polishing Cloth",1 Pcs,23.80/Pcs,23.80,"CGST @ 2.5%",,0.60,"SGST @ 2.5%",,0.60,"(No. :16532)",
1-6-2018,"(149)","","Sale",-3212.18,,"(Sale)",,3212.18,,"Diesel",46.000 Ltr,69.83/Ltr,3212.18,"(No. :16533)",

每行不以日期开头的行都会与前一行合并......

答案1

  • Ctrl+H
  • 找什么:\R(?!\d{1,2}-\d{1,2}-\d{4})
  • 用。。。来代替:LEAVE EMPTY
  • 检查环绕
  • 检查正则表达式
  • Replace all

解释:

\R          : any kind of linebreak
(?!         : start negative look ahead, make sure we don't have after:
  \d{1,2}   : 1 or 2 digits
  -         : a dash
  \d{1,2}   : 1 or 2 digits
  -         : a dash
  \d{4}     : 4 digits
)           : end lookahead (ie. a date)

给定示例的结果:

1-6-2018,"(101)","","Sale",-862.96,,"(Sale)",,837.96,,"Diesel",12.000 Ltr,69.83/Ltr,837.96,"Sales @ 5%",,23.80,,"Polishing Cloth",1 Pcs,23.80/Pcs,23.80,"CGST @ 2.5%",,0.60,"SGST @ 2.5%",,0.60,"(No. :16532)",
1-6-2018,"(149)","","Sale",-3212.18,,"Sales(Sale)",,3212.18,,"Diesel",46.000 Ltr,69.83/Ltr,3212.18,"(No. :16533)",

相关内容