Community
    • Login

    remove characters

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    9 Posts 5 Posters 434 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.
    • sir twoshedsS
      sir twosheds
      last edited by

      Is it possible to remove x number of characters from a given position within lines of text. For example, remove 6 charachters from position 7 in each line. Counting from either the beginnig or end?

      PeterJonesP Alan KilbornA 2 Replies Last reply Reply Quote 0
      • PeterJonesP
        PeterJones @sir twosheds
        last edited by

        @sir-twosheds ,

        Is it possible

        Yes.

        Search Mode = Regular Expression will help.

        data:

        abcdefghijklmnopqrstuvwxyz
        123456789x123456789x123456789x
        

        Counting from either the beginnig …

        FIND = ^(.{6}).{6}

        • ^ says “only match at beginning of the line”
        • ( … ) says “save the matched text into a numbered group for later use”
        • . says “match any character”
        • .{6} says “match six instances of any character”

        REPLACE = $1

        • $1 says “replace with the contents of group 1”

        REPLACE ALL

        data after replacing all:

        abcdefmnopqrstuvwxyz
        1234563456789x123456789x
        

        Counting from … end?

        For a different example, let’s remove 4 characters starting 7 characters before the end (so the tuvw and 4567, but keeping the stuff that came before, and keeping the last 3 characters (xyz and 89x)

        FIND = .{4}(.{3})$
        REPLACE = $1

        The only new syntax here is $ matches the end of the line, just like ^ matched the beginning.

        data after replacing all:

        abcdefghijklmnopqrsxyz
        123456789x123456789x12389x
        

        ----

        Useful References

        • Template for Search/Replace Questions
        • Notepad++ Online User Manual: Searching/Regex
        • FAQ: Where to find other regular expressions (regex) documentation
        1 Reply Last reply Reply Quote 3
        • Alan KilbornA
          Alan Kilborn @sir twosheds
          last edited by

          @sir-twosheds

          From the “beginning”, it’s probably easier to use column-block selection.
          Move your caret to line 1 column 7 and then hold Shift+Alt while pressing arrow keys to define your block that is 6 characters wide and however many lines tall you need.
          Once the block is defined, let up on all keys and then tap Delete.

          If your lines happen to all be the same length, this technique would also work for your “end” request.

          There’s also the Edit menu’s “Begin/End Column Select” when you have many lines you need to do this over.

          1 Reply Last reply Reply Quote 1
          • sir twoshedsS
            sir twosheds
            last edited by

            Thanks for the help

            Not sure if this is going to work where the say 6 characters are different in each line (for example different dates)?

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

              @sir-twosheds said in remove characters:

              Not sure if this is going to work where the say 6 characters are different in each line (for example different dates)?

              Why are you “not sure”? Because my example shows that it replaced ghijkl on the first line and 789x12 on the second line, which are quite obviously different characters. My description was highly explicit that it matches “six of any character”. That should have provided you with clarity on what was being replaced. And you could have tried it on your own data (with a backup, or using undo, in case there was a problem). There are lots of things in life with large uncertainty attached, but the uncertainty on this should have started quite small, and been taken to nearly 0 once you tried it and saw it worked.

              And Alan’s was even less uncertain, because his method doesn’t even require a search/replace expression, and is just making use of the powers of column-mode/rectangular selection, so wouldn’t care at all as to what the text looked like.

              dr ramaanandD 1 Reply Last reply Reply Quote 1
              • dr ramaanandD
                dr ramaanand @PeterJones
                last edited by

                @sir-twosheds It will help us if you give us what you want to start with and the desired result/output

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

                  Hello, @sir-twosheds and All,

                  Oh…, I see that it’s already solved by many people !

                  As said by @peterjones, the Regular expression search mode is your friend for such cases !


                  Let’s suppose this INPUT text, which comes from the change.log file of the N++ v.8.7.4 release :

                  Notepad++ v8.7.4 regression-fix & bug-fixes:
                  
                  1. Fix regression of multi-line tabbar height not updated after closing tabs.
                  2. Fix the extension defined by user not override language default extensions.
                  3. Fix encoding of nfo file cannot be changed bug.
                  
                  • To delete the first three characters of each line, use the following regex S/R :

                    • SEARCH (?-s)^.{3}(.*)

                    • REPLACE $1

                  And you get this OUTPUT text :

                  epad++ v8.7.4 regression-fix & bug-fixes:
                  
                  Fix regression of multi-line tabbar height not updated after closing tabs.
                  Fix the extension defined by user not override language default extensions.
                  Fix encoding of nfo file cannot be changed bug.
                  
                  • To delete the last three characters, use the following regex S/R :

                    • SEARCH (?-s).{3}$

                    • REPLACE Leave EMPTY

                  And you get this OUTPUT text :

                  Notepad++ v8.7.4 regression-fix & bug-fix
                  
                  1. Fix regression of multi-line tabbar height not updated after closing ta
                  2. Fix the extension defined by user not override language default extensio
                  3. Fix encoding of nfo file cannot be changed b
                  
                  • To delete six characters from position 7 , use the following regex S/R :

                    • SEARCH (?-s)^(.{6}).{6}

                    • REPLACE $1

                  And you get this OUTPUT text :

                  Notepa.7.4 regression-fix & bug-fixes:
                  
                  1. Fixssion of multi-line tabbar height not updated after closing tabs.
                  2. Fixxtension defined by user not override language default extensions.
                  3. Fixing of nfo file cannot be changed bug.
                  
                  • To delete six characters, starting from position 7 from the end, use the following regex SR :

                    • SEARCH (?-s).{6}(.{6})$

                    • REPLACE $1

                  And you get this OUTPUT text :

                  Notepad++ v8.7.4 regression-fix fixes:
                  
                  1. Fix regression of multi-line tabbar height not updated after c tabs.
                  2. Fix the extension defined by user not override language defaultsions.
                  3. Fix encoding of nfo file cannot be d bug.
                  

                  Best Regards,

                  guy038

                  1 Reply Last reply Reply Quote 1
                  • sir twoshedsS
                    sir twosheds
                    last edited by

                    thanks for all your help but you are all speaking a foreign language. I am a normal computer user not a computer programmer so I have no idea what you are talking about

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

                      @sir-twosheds ,

                      I told you the FIND and REPLACE and the MODE.

                      Looking at the Replace dialog (Find > Replace), we can then see where each piece of the answer goes:
                      a46e0933-2c4d-4d2c-a307-c9830e31c207-image.png

                      What I called FIND and @guy038 called SEARCH goes in the Find what field in the dialog. What I and @guy038 each called REPLACE goes in the Replace with field in the dialog. What I called the MODE is the Search Mode set of radio buttons, and that needs to be set to Regular expression (as shown in my screenshot). Then to do the replacement, you hit the Replace All button. This is shown below:

                      6022c38f-7bb6-4a22-9c5d-769493f7c298-image.png

                      Even if you choose to not try to understand the syntax (despite the fact that @guy038 and I both went to lengths to explain every part of the syntax we shared, and I provided you with links where to learn more), I gave you the exact fill-in-the-blanks to do it without any learning on your point, so you can use either of the answers we gave.

                      To claim that our answers are not helpful because “I am a normal computer user… so I have no idea what you are talking about” is not reasonable. Our answers provided the FIND and REPLACE fields that you needed, without requiring any understanding of the syntax we told you to use, and only requiring you to be able to figure out that FIND or SEARCH maps to Find what and REPLACE maps to Replace with which is not a difficult ask for a “normal computer user”. It is also lying to yourself about your own abilities – you can figure out how to implement the solutions that @guy038 and I described, as can anyone who can follow reasonable directions. If you choose to lie to yourself and tell yourself that you cannot learn the specifics of the syntax, that is your choice (though a bad one): if you choose to believe that lie, then you can just take the solution we gave you and use it, without learning what it means, meaning that you will not be able to replicate similar results for slight changes in your desires in the future, but it will solve your immediate problem.

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