Community
    • Login

    Regex help

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    5 Posts 3 Posters 666 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.
    • Jose Emilio OsorioJ
      Jose Emilio Osorio
      last edited by

      Good Afternoon,
      Using Regex: How to replace with space blank the characters from position 25 to position 43 in a entire rows of a file ?
      Thanks.

      PeterJonesP 1 Reply Last reply Reply Quote 1
      • PeterJonesP
        PeterJones @Jose Emilio Osorio
        last edited by PeterJones

        @jose-emilio-osorio

        FIND = (?-s)^.{24}\K.{18}
        REPLACE = \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20 (using \x20 instead of spaces for easy copy/paste from the forum; it will work either as 18 copies of \x20 or 18 spaces in the replacement field; \x20 is another way of saying the-space-character)
        SEARCH MODE = regular expression
        REPLACE ALL

        This will replace 25 (one more than 24 in the braces) to 43 (which is a total of 18 characters) with 18 spaces

        ----

        Useful References

        • Please Read Before Posting
        • Template for Search/Replace Questions
        • FAQ: Where to find regular expressions (regex) documentation
        • Notepad++ Online User Manual: Searching/Regex
        Jose Emilio OsorioJ 1 Reply Last reply Reply Quote 1
        • Jose Emilio OsorioJ
          Jose Emilio Osorio @PeterJones
          last edited by

          @peterjones Thank you.

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

            Hello, @jose-emilio-osorio, @peterjones and All,

            As the OP want to replace the 43th column with a space char, as well, I suppose that the correct regex S/R is :

            • SEARCH (?-s)^.{24}\K.{19}

            • REPLACE \x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20


            Now, here is a workaround when the REPLACE field must contain some space characters :

            SEARCH   :   (?-s)^.{24}\K.{19}
            
            REPLACE  :   (                   )
            
            • Tick the Wrap around option

            • Select the Regular expression search mode

            • Click once on the Replace All button ( Do not use the Replace button, because of the \K feature )

            Best Regards,

            guy038

            P.S. :

            For instance, you could use this regex S/R :

            SEARCH   :   (?-s)^.{24}\K.{19}
            
            REPLACE  :   (   text replaced   )
            
            PeterJonesP 1 Reply Last reply Reply Quote 2
            • PeterJonesP
              PeterJones @guy038
              last edited by

              @guy038 , @Jose-Emilio-Osorio

              Stupid fence post. In my head while answering, I knew to add 1 to account for the 25::43 inclusive, but I obviously didn’t execute that +1 before typing up the reply. Sorry for the off-by-one error.

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