如何删除列CSV记事本++ / RegEx? [英] How to remove columns CSV Notepad++ / RegEx?
问题描述
a,b,c,d
aaa,2.15,100.15, -
bbb,3.16,215.16, -
ccc,4.10,365.18 , -
我要删除
2.15,
3.16,
4.10,
和
, -
, -
, -
我要删除栏b + d
\w]。*,[\ w]。
解决方案b $ b(编辑:添加
\r\\\
所以不要跨越行)
X =在col 1之前:= b-1
Y =在col 2之前:= d-1 - X - 1
查找:
(?m)^((?:[^,\r\\\
] *,){X})[^,\r\ n] *,((?:[^,\r\\\
] *,){Y})[^,\r\\\
] *(。*)
取代:
$ 1 $ 2 $ 3
X = 2-1(Col 2)= 1
Y = 4-1 - X - 1(第4列) = 1
正则表达式:
(?m)^((?:[^,\r\\\
] *, )[^,\r\\\
] *,((?:[^,\r\\\
] *,){1})[^,\r\\\
] * / code>
或者,如果这是一次性活动,请使用
(?m)^([^,\r\\\
] *,)[^,\r\\\
] *, \r\\\
] *)。*
替换
$ 1 $ 2
/ p>
这只是消除了列2和4.
a,b,c,d aaa,2.15,100.15,- bbb,3.16,215.16,- ccc,4.10,365.18,-
I want to remove
2.15, 3.16, 4.10,
and
,- ,- ,-
I want to remove columns b + d
,[\w].*,[\w].
解决方案Just capture everything but the two columns.
(Edit: added\r\n
so don't span lines)X = Before col 1: = b-1
Y = Before col 2: = d-1 - X - 1Find:
(?m)^((?:[^,\r\n]*,){X})[^,\r\n]*,((?:[^,\r\n]*,){Y})[^,\r\n]*(.*)
Replace:
$1$2$3
Example -
X = 2-1 (Col 2) = 1
Y = 4-1 - X - 1 (Col 4) = 1Regex:
(?m)^((?:[^,\r\n]*,){1})[^,\r\n]*,((?:[^,\r\n]*,){1})[^,\r\n]*(.*)
Or, if this is a 1-off thing, use
(?m)^([^,\r\n]*,)[^,\r\n]*,([^,\r\n]*).*
Replace
$1$2
Which just eliminates column's 2 and 4.
这篇关于如何删除列CSV记事本++ / RegEx?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!