Community
    • Login

    Help with deleting the the first three lines and the last four lines as a batch for 200 files

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 18 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      Skyyblaze
      last edited by

      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!

      PeterJonesP 1 Reply Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @Skyyblaze
        last edited by PeterJones

        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 match a or b or c, so for the exact three you said, it would be (45/23|31/89|21/77) as the FIND and 66/55 as the replace.

        But if you’re not describing it well, and you just want any two-digit fractions of the form ##/## to be replaced with 66/55, then it would be \d\d/\d\d (where \d is 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}\Z will 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 newline enabled)

        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 \A or \Z or 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

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • Formatting Forum Posts
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        1 Reply Last reply Reply Quote 0
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors