简体   繁体   English

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

[英]How do I remove everything beyond the second occurrence of a character using Regex?

I have a list that is something like:我有一个类似的列表:

xxxxx|xxxxxx|xxxxx@example.com
xxxxx|xxxxxx|xxxxx@example.com
xxxxx|xxxxxx|xxxxx@example.com

The x's can be both letters and numbers, but nothing else. x 既可以是字母也可以是数字,但不能是别的。

What I am trying to do is replace everything (including the character) to the right of the second |我要做的是替换第二个右侧的所有内容(包括字符) | . . The outcome should look like:结果应如下所示:

xxxxx|xxxxx

I want to do it with regex so that I can replace all the occurrences in Notepad++.我想用正则表达式来做,这样我就可以替换 Notepad++ 中的所有出现。

Find寻找

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

Replace with用。。。来代替

\1

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

Replace \|[^\|]+$ with nothing.\|[^\|]+$替换为空。

This will match |xxxxx@example.com , so if you replace it with a blank string, that will accomplish what you want.这将匹配|xxxxx@example.com ,所以如果你用空白字符串替换它,那将完成你想要的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 sed/grep/regex 在第 3 次第 4 次出现字符后删除所有内容 - How do I delete everything after the 3rd 4rth occurrence of a character using sed/grep/regex 如何使用正则表达式匹配和复制所有字符,直到首次出现一个字符? - How to match and copy everything up to first occurrence of a character using regex? 如何将所有内容匹配到字符的第二次出现? - How to match everything up to the second occurrence of a character? 如何使用正则表达式删除字符串中括号外的所有内容 - How do I remove everything outside of parenthesis in a string using regex 如何使用正则表达式在倒数第二次出现之前获取所有内容? - How to get everything before the second-to-last occurrence with a regex? 正则表达式替换第二次出现的字符 - Regex to replace second occurrence of a character 如何在 splunk 中第一次出现字符之前删除所有内容 - How to remove everything before first occurrence of a character in splunk 如何使用正则表达式检测第二次出现? (php) - How to detect second occurrence using regex? (php) 如何在 Javascript 中使用 REGEX 删除空格、括号和中间的所有内容 - How do I remove spaces, brackets and everything in between using REGEX in Javascript 在 Google 表格中使用正则表达式如何删除 &lt;&gt; 字符中的所有内容,包括字符本身? - Using regex in Google Sheets how do I remove everything within the <> characters, including the characters themselves?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM