Community

    • Login
    • Search
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    How to eliminate lines that meet a specific condition with Notepad?

    General Discussion
    3
    6
    1991
    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.
    • oscar remiccc
      oscar remiccc last edited by

      Hi, friends I need to eliminate the lines that meet the following conditions

      1john1:9678sharp
      Karly:
      woman:7890test
      logomen:dream
      :hitman
      lvely:

      to

      1john1:9678sharp

      woman:7890test
      logomen:dream

      try it with: (\s:.)([^\s]+) just delete the right side of “:”

      Any friends idea?

      1 Reply Last reply Reply Quote 0
      • guy038
        guy038 last edited by guy038

        Hi, @oscar-remiccc and All,

        Apparently, I understand that you would like to delete every line, ending with the colon : character

        Easy, with regular expressions !

        • Open the Replace dialog

        • Select the Regular expression search mode

        • Tick, if necessary, the Wrap around option

        SEARCH (?-s).*:\R

        REPLACE Leave EMPTY

        • Click once, on the Replace All button or several times, on the Replace button

        Notes :

        • The first part (?-s) means that dot, ., matches any single standard character, only ( not EOL ones )

        • The middle part .*: tries to match the longest range of characters, even null, before a colon character

        • The final part \R matches any kind of line-break ( \r\n in Windows files, \n in Unix files and \r in Mac files )

        • Note that the last line, of your file, must be followed with a line-break ( Just in case this last line would end with a colon character : !

        Cheers,

        guy038

        Scott Sumner 1 Reply Last reply Reply Quote 1
        • Scott Sumner
          Scott Sumner @guy038 last edited by

          @guy038 said:

          I understand that you would like to delete every line, ending the colon : character

          :hitman doesn’t end with a : (although it begins with one) and it appears to not be in the OP’s desired output…

          Maybe best to wait for OP’s clarification rather than guess, though.

          1 Reply Last reply Reply Quote 1
          • oscar remiccc
            oscar remiccc last edited by

            thanks friends, excuse me for letting me understand
            I need to eliminate lines that are not complete like this:

            Karly:
            :hitman
            lvely:

            example file containing :

            1john1:9678sharp
            Karly:
            woman:7890test
            logomen:dream
            :hitman
            lvely:

            Needed result:

            1john1:9678sharp
            woman:7890test
            logomen:dream

            my file contains more than 60000 lines

            thanks you

            Scott Sumner 1 Reply Last reply Reply Quote 0
            • Scott Sumner
              Scott Sumner @oscar remiccc last edited by

              @oscar-remiccc

              Try this to do it all at once (…or use @guy038’s solution twice with a slight change for the second run):

              Invoke Replace dialog (default key: ctrl+h)
              Find what zone: ^((:.+)|(.+:))(\R|\z)
              Replace with zone: make sure this box is EMPTY
              Wrap around checkbox: ticked
              Search mode selection: Regular expression
              Action: Press Replace All button

              Here’s how it works, the Find part anyway…the Replace part containing nothing simply removes the text matched by the Find part…note that I used capturing groups rather than non-capturing because the non-capturing symbology contains a : and that probably would make things look more confusing because of the literal : in the data:

              ^((:.+)|(.+:))(\R|\z)

              • [Assert position at the beginning of a line (at beginning of the string or after a line break character) (carriage return and line feed, form feed)][1 ] ^
              • [Match the regex below and capture its match into backreference number 1][2 ] ((:.+)|(.+:))
                • [Match this alternative (attempting the next alternative only if this one fails)][3 ] (:.+)
                  • [Match the regex below and capture its match into backreference number 2][2 ] (:.+)
                    • [Match the colon character][4 ] :
                    • [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][5 ] .+
                      • [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][6 ] +
                • [Or match this alternative (the entire group fails if this one fails to match)][3 ] (.+:)
                  • [Match the regex below and capture its match into backreference number 3][2 ] (.+:)
                    • [Match any single character that is NOT a line break character (line feed, carriage return, form feed)][5 ] .+
                      • [Between one and unlimited times, as many times as possible, giving back as needed (greedy)][6 ] +
                    • [Match the colon character][4 ] :
              • [Match the regex below and capture its match into backreference number 4][2 ] (\R|\z)
                • [Match this alternative (attempting the next alternative only if this one fails)][3 ] \R
                  • [Match a line break (carriage return and line feed pair, sole line feed, sole carriage return, vertical tab, form feed)][7 ] \R
                • [Or match this alternative (the entire group fails if this one fails to match)][3 ] \z
                  • [Assert position at the very end of the string][8 ] \z

              Created with RegexBuddy

              [1 ]: http://www.regular-expressions.info/anchors.html
              [2 ]: http://www.regular-expressions.info/brackets.html
              [3 ]: http://www.regular-expressions.info/alternation.html
              [4 ]: http://www.regular-expressions.info/characters.html
              [5 ]: http://www.regular-expressions.info/dot.html
              [6 ]: http://www.regular-expressions.info/repeat.html
              [7 ]: http://www.regular-expressions.info/nonprint.html
              [8 ]: http://www.regular-expressions.info/anchors.html#az

              RegexBuddy settings to emulate N++ regex engine: Application=boost::regex 1.54-1.57 / flavor=Default flavor / replacement flavor=All flavor / ^$ match at line breaks / Numbered capture / Allow zero-length matches

              1 Reply Last reply Reply Quote 2
              • oscar remiccc
                oscar remiccc last edited by

                @Scott-Sumner said:

                ^((:.+)|(.+:))(\R|\z)

                I appreciate your help friends

                1 Reply Last reply Reply Quote 1
                • First post
                  Last post
                Copyright © 2014 NodeBB Forums | Contributors