Community
    • Login

    Regex Help Wanted - Delete all lines containing "STRING"

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    7 Posts 4 Posters 859 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.
    • Gary SmithG
      Gary Smith
      last edited by

      I have an output file created by program A that is then read by program B.

      Program A generates and appends each file with “System Tag ID-DD/MM/YYYY”, these files can be in batches of 10 -> 1000

      Program B does not appreciate this “erroneous” data so throws a wobbly when the file is imported.

      I have no control over the source code for either program so cannot either of them to play nice.

      Using N++, how would I go about using a regex to find each line containing the string “System Tag” then deleting that line in every open file?

      I’ve been googling and found a few methods but none of them seem to search past the first line or return the results needed, so im obviously missing something huge

      for example I found this on this community but adapting it fails to find any results (?i-s)^.MeX.\R (It is supposed to find each line containing MeX in any case and replace the line with BLANK when replace is used

      Thank guys

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA
        Alan Kilborn @Gary Smith
        last edited by

        @Gary-Smith

        how would I go about using a regex to find each line containing the string “System Tag” then deleting that line in every open file?

        Search for: (?-is)^.*?System Tag.*\R and replace with nothing.
        Use the Replace All in All Opened Documents button.

        Gary SmithG 1 Reply Last reply Reply Quote 2
        • Phillip StanhopeP
          Phillip Stanhope
          last edited by

          Can I suggest the “Sed” utility?
          sed “/Regex/d” InFile > OutFile
          “d” deletes the line containing the Regex.
          Alternatively : sed -i “/Regex/d” FileName - “-i” changes the <file> in place.
          Also : sed -i -r (extended Regex)
          I use a .bat that requests the Input and Output file names, copies the Input file to the Output file and then does lots of substitutions. However Sed then creates a temporary file “Sedxxx” for each command which then need deleting.
          If you have many files, you can create a DOS .bat file to process all files within a folder using the “FOR” command.
          WIndows 7, Sed for windows.

          Alan KilbornA 1 Reply Last reply Reply Quote 0
          • Alan KilbornA
            Alan Kilborn @Phillip Stanhope
            last edited by

            @Phillip-Stanhope said in Regex Help Wanted - Delete all lines containing "STRING":

            Can I suggest the “Sed” utility?

            You can, but really people are coming here looking for solutions to problems with the solutions involving Notepad++.

            Directing them to non-Notepad++ utilities, when there are ways to do what they are requesting within Notepad++, is considered bad form and off-topic.

            1 Reply Last reply Reply Quote 3
            • Gary SmithG
              Gary Smith @Alan Kilborn
              last edited by

              @Alan-Kilborn Thanks for this alan, but think i’m missing something and just can’t get this to work. I have included a screenshot for the exact method im using and it still returns no results in the “replace” dialog box.

              Do you have any ideas where I could be going wrong?

              2021-08-27_15-00-07.jpg

              PeterJonesP 1 Reply Last reply Reply Quote 1
              • PeterJonesP
                PeterJones @Gary Smith
                last edited by PeterJones

                @Gary-Smith said in Regex Help Wanted - Delete all lines containing "STRING":

                Do you have any ideas where I could be going wrong?

                Your last line, which is the one that has System Tag on it, does not have a newline sequence, so \R has nothing to match. (?-is)^.*?System Tag.*(\R|\z) should work (see “Anchors” in the usermanual regex section)

                Gary SmithG 1 Reply Last reply Reply Quote 1
                • Gary SmithG
                  Gary Smith @PeterJones
                  last edited by

                  @PeterJones said in Regex Help Wanted - Delete all lines containing "STRING":

                  (?-is)^.?System Tag.(\R|\z)

                  Worked flawlessly , thanks a lot folks for all your help, just saves me a whole bunch of work :)

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post
                  The Community of users of the Notepad++ text editor.
                  Powered by NodeBB | Contributors