简体   繁体   中英

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.

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++.

Find

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

Replace with

\1

Reference: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM