Community
    • Login

    Trim length between two characters

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    6 Posts 4 Posters 1.2k Views 2 Watching
    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.
    • SeanS Offline
      Sean
      last edited by

      What I need to do is trim the last character between the , and , if the length is 12 or greater which would then make the length 11.

      This is before

      #,610079544260,1
      #,205300099864,1
      #,65433455333,5
      #,205300022008,1
      #,3360,20
      #,718103267854,2
      #,67764334775,8

      This is what it should look like after

      #,61007954426,1
      #,20530009986,1
      #,65433455333,5
      #,20530002200,1
      #,3360,20
      #,71810326785,2
      #,67764334775,8

      Thank you

      Alan KilbornA 1 Reply Last reply Reply Quote 0
      • Alan KilbornA Offline
        Alan Kilborn @Sean
        last edited by

        @Sean

        You might try:

        Find: ^(#,\d{11})\d(?=,)
        Replace: \1
        Search mode: Regular expression

        1 Reply Last reply Reply Quote 1
        • SeanS Offline
          Sean
          last edited by Sean

          @Alan-Kilborn

          Perfect thank you very much.

          1 Reply Last reply Reply Quote 1
          • Steven HaymesS Offline
            Steven Haymes
            last edited by Steven Haymes

            If the file is not too long, you can always use Column Mode with the Alt key. I do similar operations on CSV files all the time. Regular expressions are more elegant though.

            Alan KilbornA 1 Reply Last reply Reply Quote 1
            • Alan KilbornA Offline
              Alan Kilborn @Steven Haymes
              last edited by

              @Steven-Haymes

              I made the assumption that the OP may have other lines (that are longer) intermingled with the ones shown that he doesn’t want affected. Otherwise, yes, you are right, this is a good application of column mode editing, perhaps in combination with the Begin/End Select command, which also works with column mode editing, although it is a bit obscure (you have to get into column mode as you are positioning the caret for the “end select”).

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

                Hello, @sean, @alan-kilborn, @steven-haymes, and All,

                I’m afraid that, in order to use the column mode, in a reliable way, we should align the comma symbols, padding preceding positions with spaces chars !

                So, this time, the regex solution seems to be more secure ;-))

                For instance, with that sample text, below :

                #,6100795442608787,1
                #,205300099864,1
                #,65433455333,5
                #,20530002200815618844,1
                #,3360,20
                #,718103267854,2
                #,67764334775,8
                

                Here is a regex S/R which deletes any non-null range of digits, after the 11th, till the second comma of each line :

                • SEARCH ^#,\d{11}\K\d+(?=,)

                • REPLACE Leave EMPTY

                • Tick the Wrap around

                • Select the Regular expression search mode

                • Click, exclusively, on the Replace All button

                And, we would obtain the expected result :

                #,61007954426,1
                #,20530009986,1
                #,65433455333,5
                #,20530002200,1
                #,3360,20
                #,71810326785,2
                #,67764334775,8
                

                Best Regards,

                guy038

                1 Reply Last reply Reply Quote 1

                Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                With your input, this post could be even better 💗

                Register Login
                • First post
                  Last post
                The Community of users of the Notepad++ text editor.
                Powered by NodeBB | Contributors