问题
I would like to replace all the characters occurring between second and third pipe character. Example:
|hello|welcome,to|
In this I want replace welcome,to
with a blank value, with a huge file to be replaced. I need a regex pattern to be used in notepad++.
回答1:
Assuming you're parsing each line, i.e. a token cannot include a newline:
Find what:
^((?:[^|\n]*\|){2})[^|\n]*+\|
Replace with:
$1|
Description
^
- matches the start of line((?:[^|\n]*\|){2})
- matches and captures in group 1:(?:[^|\n]*\|){2}
the following expression repeated twice[^|\n]*
- any character except a pipe or a newline\|
- followed by a pipe
[^|\n]*+
- the token you want to remove (any char except pipe or newline)\|
- followed by a pipe
回答2:
In notepad++ use this regex for search:
^([^|]*\|[^|]*\|)[^|]*
And replace by:
$1
([^|]*\|[^|]*\|)
matches and captures text before 2nd |
into a capturing group #1.
RegEx Demo
来源:https://stackoverflow.com/questions/40067431/how-to-replace-all-string-between-second-and-third-occurance-of-pipe-character-u