在第33个逗号后替换所有内容

时间:2019-01-25 15:40:39

标签: notepad++

我在Notepad ++中打开了一个csv文件。标头有33个逗号,这意味着它有34列。但是,在500k行中,只有7k行包含33个逗号-其他行都有更多逗号。对于每一行,我都需要删除incl。之后的所有内容。第34个逗号。

我用搜索找到了以下几行:^ [^,\ n] ((,[^,\ n] ){33} $)

在“替换”框中,我需要类似以下内容:\ 1保留找到的字符串,但是如何删除其余字符串?

^[^,\n]*((,[^,\n]*){33}$)

1 个答案:

答案 0 :(得分:1)

您“亲密接触,只需稍加修改,即可使用:

  • Ctrl + H
  • 查找内容:^[^,\r\n]*(?:,[^,\r\n]*){33}\K.*$
  • 替换为:LEAVE EMPTY
  • 检查环绕
  • 检查正则表达式
  • 取消检查. matches newline
  • 全部替换

说明:

^               # beginning of line
  [^,\r\n]*     # 0 or more any character except comma and linebreak
  (?:           # non capture group
    ,           # a comma
    [^,\r\n]*   # 0 or more any character except comma and linebreak
  ){33}         # end group, appears 33 times
  \K            # forget all we've seen until this position
  .*            # 0 or more any character but newline
$               # end of line