如何使用正则表达式删除字符第二次出现之外的所有内容?

问题描述 投票:0回答:2

我有一个类似的列表:

xxxxx|xxxxxx|[email protected]
xxxxx|xxxxxx|[email protected]
xxxxx|xxxxxx|[email protected]

x 可以是字母和数字,但不能是其他。

我想做的是替换第二个

|
右侧的所有内容(包括该字符)。结果应该是这样的:

xxxxx|xxxxx

我想用正则表达式来实现,这样我就可以替换Notepad++中出现的所有内容。

regex filter notepad++
2个回答
7
投票

寻找

^([^|]*|[^|]*)|.*$

替换为

\1

参考:http://www.scintilla.org/SciTERegEx.html


4
投票

\|[^\|]+$
替换为任何内容。

这将匹配

|[email protected]
,因此如果将其替换为空白字符串,即可实现您想要的效果。

© www.soinside.com 2019 - 2024. All rights reserved.