我在Notepad ++中打开了一个csv文件。标头有33个逗号,这意味着它有34列。但是,在500k行中,只有7k行包含33个逗号-其他行都有更多逗号。对于每一行,我都需要删除incl。之后的所有内容。第34个逗号。
我用搜索找到了以下几行:^ [^,\ n] ((,[^,\ n] ){33} $)
在“替换”框中,我需要类似以下内容:\ 1保留找到的字符串,但是如何删除其余字符串?
^[^,\n]*((,[^,\n]*){33}$)
答案 0 :(得分:1)
您“亲密接触,只需稍加修改,即可使用:
^[^,\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