Help with deleting the the first three lines and the last four lines as a batch for 200 files
-
Hey Notepad++ Community! I’ve been using NP++ for ages now and it’s great but I ran into a bit of trouble setting a RegEx for Search and Replace correctly even after searching around. I have two different things I want to do with it:
1: How can I tell NP++ to search for multiple different text snippets at once? For example all instances of 45/23 31/89 and 21/77 should all be replaced with 66/55
2: How can I tell NP++ to delete the first three lines and the last four lines (the last line is always empty) of a file?
Thanks for help in advance!
-
1: How can I tell NP++ to search for multiple different text snippets at once? For example all instances of 45/23 31/89 and 21/77 should all be replaced with 66/55
(a|b|c)will matchaorborc, so for the exact three you said, it would be(45/23|31/89|21/77)as the FIND and66/55as the replace.But if you’re not describing it well, and you just want any two-digit fractions of the form
##/##to be replaced with66/55, then it would be\d\d/\d\d(where\dis regex-speak for “any digit”)If neither of those is what you really want, you will need to give more examples of what should and shouldn’t match.
2: How can I tell NP++ to delete the first three lines and the last four lines (the last line is always empty) of a file?
First three lines: FIND
\A(^.*?\R){3}will match the start of file and the first three lines, and replacing that with empty text will delete them.Last four: FIND
(^.*?\R){4}\Zwill match four lines and the end-of-file, so replacing that with empty text will delete them.Fancy: do both with the
|to say “either/or”, so FIND =\A(^.*?\R){3}|(^.*?\R){4}\Z(don’t have
. matches newlineenabled)All of that syntax is described in the User Manual regex section, so if you want more details, you can load that page and use your browser to search for
\Aor\Zor similar; the concepts used were anchors (for beginning/end of file), multiplying operators (for doing N lines), and groups (so the multiplying operators apply to the entire-line matcher)200 files
Regex will work in the Find in Files, which is how you make it apply to that many files. But try it in one open file first, to make sure it does exactly what you think. And for bulk operations, always keep a backup, in case things don’t go as you expected.
----
Useful References