64

I was trying to find a solution for my problem.

Input:

This is the sample title | mypcworld

Output:

This is the sample title

I want to remove everything comes after " | " using simple regex on notepad++ It seems to be really simple one. But I was tried with some other regex "|.*$" listed on here, but no luck. The problem was the character "|" was alteration equivalent of or. So please help me to solve it.

3

3 Answers 3

137

The pipe, |, is a special-character in regex (meaning "or") and you'll have to escape it with a \.

Using your current regex:

\|.*$

I've tried this in Notepad++, as you've mentioned, and it appears to work well.

2
  • 6
    For some reason this gives me the complete OPPOSITE of what the question is asking... ???
    – CodeCamper
    Commented Jun 19, 2018 at 2:54
  • 1
    @Radioactive, the question is asking about "removing" everything after the | in Notepad++. If you Ctrl+H (for find + replace), enter my suggestion here in the "Find what" field and use an empty string for the "Replace with" field, make sure "Regular expression" is selected and click the "Replace" button, it should work as described. I just tested again and 7 years later, it still works =] Commented Feb 10, 2020 at 15:34
18

If you want to get everything after | excluding set character use this code.

[^|]*$

Others solutions \|.*$

Results : | mypcworld

This one [^|]*$

Results : mypcworld

http://regexr.com/3elkd

1
  • [^|]*$ this worked very well for me. Why doesn't ^.*$ work, though? It specifies it can start and end with any character "." but it doesn't find anything, at least for my AegiSub program Commented Jan 15, 2019 at 4:22
7

In a .txt file opened with Notepad++,
press Ctrl-F
go in the tab "Replace"
write the regex pattern \|.+ in the space Find what
and let the space Replace with blank

Then tick the choice matches newlines after the choice Regular expression
and press two times on the Replace button

1
  • in Notepad++, CRTL+H will directly go to "Replace" tab so instead of CRTL+F and changing to "Replace" tab - one can use that one.
    – nanosoft
    Commented Nov 23, 2018 at 11:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.