How can I remove everything in brackets or a particular word and beyond in Notepad++?
I need to omit everything from (
and beyond, or everything from http
and beyond
Menu "Search" > "Replace" (or Ctrl + H)
Set "Find what" to
\(.*?$|http.*?$
Leave "Replace with" empty
Enable "Regular expression"
-
Click "Replace All"
Before:
PCSH10160 Attack of the Toy Tanks (3.61+!) [3.69] http://zeu
PCSH10162 Paradox Soul http://zeus.dl.playstation.net/cdn
PCSH10146 Hoggy2 http://zeus.dl.playstation.net/cdn/HP2005/
PCSB01394 Mekabolt http://zeus.dl.playstation.net/cdn/EP0
PCSH10186 Himno http://zeus.dl.playstation.net/cdn/HP2
PCSG01285 MELLKISS http://zeus.dl.playstation.net/cdn/JP0
PCSB01365 Habroxia http://zeus.dl.playstation.net/cdn/EP5
PCSE01423 Color Slayer http://zeus.dl.playstation.net/cdn
PCSE01396 Habroxia http://zeus.dl.playstation.net/cdn/UP4
PCSG01127 Sen no Hatou, Tsukisome no Kouki http://zeus.dl
PCSB01396 Tic-Tac-Letters by POWGI http://zeus.dl.playsta
PCSH10203 Gravity Duck http://zeus.dl.playstation.net
PCSH10175 Crossovers by POWGI http://zeus.dl.playstation
PCSH10169 Mixups by POWGI (3.61+!) [3.69] http://zeus.dl
PCSH10167 One Word by POWGI http://zeus.dl.playstation
PCSH10166 Word Search by POWGI http://zeus.dl.playsta
PCSH10179 Word Wheel by POWGI http://zeus.dl.playstation
PCSH10180 Wordsweeper by POWGI http://zeus.dl.playsta
PCSH10168 Word Sudoku by POWGI http://zeus.dl.playsta
PCSB00625 SENRAN KAGURA: Bon Appétit! Stacked Soundtrack ht
After:
PCSH10160 Attack of the Toy Tanks
PCSH10162 Paradox Soul
PCSH10146 Hoggy2
PCSB01394 Mekabolt
PCSH10186 Himno
PCSG01285 MELLKISS
PCSB01365 Habroxia
PCSE01423 Color Slayer
PCSE01396 Habroxia
PCSG01127 Sen no Hatou, Tsukisome no Kouki
PCSB01396 Tic-Tac-Letters by POWGI
PCSH10203 Gravity Duck
PCSH10175 Crossovers by POWGI
PCSH10169 Mixups by POWGI
PCSH10167 One Word by POWGI
PCSH10166 Word Search by POWGI
PCSH10179 Word Wheel by POWGI
PCSH10180 Wordsweeper by POWGI
PCSH10168 Word Sudoku by POWGI
PCSB00625 SENRAN KAGURA: Bon Appétit! Stacked Soundtrack ht
Note:
- The last example line is not correct but will be when you apply against the untruncated file.
- To truncate the lines containing MISSING change "Find what" to
\(.*?$|http.*?$|MISSING.*?$
Following conversations in the comments the fastest regular expression is
\h+(?:\(|http|MISSING).+$
Further reading
- FAQ Desk: Where to find REGEX documentation ? | Notepad++ Community
- Notepad++: A guide to using regular expressions and extended search mode
- Regular Expressions Tutorial
- RegExr: Learn, Build, & Test RegEx
- regex101: Online regex tester and debugger
Improve performance (thanks to @IsmaelMiguel) & answer new requierement.
- Ctrl+H
- Find what:
\h+(?:\(|http|MISSING).+$
- Replace with:
LEAVE EMPTY
- CHECK Match case
- CHECK Wrap around
- CHECK Regular expression
-
UNCHECK
. matches newline
- Replace all
Explanation:
\h+ # 1 or more horizontal spaces
(?: # non capture group
\( # opening parenthesis
| # OR
http # literally
| # OR
MISSING # literally
) # end group
.+ # 1 or more any character but newline
$ # end of line
Screenshot (before):
Screenshot (after):