• Login
Community
  • Login

I need to delete two characters in two continuous lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
12 Posts 6 Posters 1.4k 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.
  • B
    Billy Martin
    last edited by May 6, 2019, 8:24 PM

    Hi, I need your help to solve one, I suppose, single thing… I have some files with data in this format:
    [
    -90.67575919025678,
    14.12140539076991,
    0
    ],
    [
    -90.67691295444409,
    14.11436171657998,
    0
    ],
    …

    The thing is that I need to delete the last two characters in the square brackets the “,” and the “0”, so it must seem like:

    [
    -90.67575919025678,
    14.12140539076991
    ],
    [
    -90.67691295444409,
    14.11436171657998
    ],

    Any suggestion on how can I do that?

    Thanks,

    Billy

    A 1 Reply Last reply May 6, 2019, 8:33 PM Reply Quote 0
    • A
      Alan Kilborn @Billy Martin
      last edited by May 6, 2019, 8:33 PM

      @Billy-Martin

      Well, if all your data is really that simple, this seems to match it:

      FInd ,\R0\R(?=\])
      Search mode: Regular expression

      You can replace it with “nothing”.

      I’d be careful using it, though. There might be more to the story that you haven’t told us.

      1 Reply Last reply Reply Quote 3
      • B
        Billy Martin
        last edited by May 6, 2019, 8:45 PM

        Thanks Alan, I’ve tried that expression but it says that cannot find the text.

        A M 2 Replies Last reply May 6, 2019, 8:47 PM Reply Quote 0
        • A
          Alan Kilborn @Billy Martin
          last edited by May 6, 2019, 8:47 PM

          @Billy-Martin

          I copied the original text you gave out of the forum and into Notepad++. Then I used the Find expression I provided. It matched for me.

          1 Reply Last reply Reply Quote 1
          • K
            Karsten75
            last edited by May 6, 2019, 8:55 PM

            Just tried it the same as Alan, it worked for me and reported that two occurrences were found/deleted.

            1 Reply Last reply Reply Quote 0
            • M
              Meta Chuh moderator @Billy Martin
              last edited by May 6, 2019, 9:00 PM

              @Billy-Martin

              your original text is:

              [
                            -90.67575919025678,
                            14.12140539076991,
                            0
                          ],
                          [
                            -90.67691295444409,
                            14.11436171657998,
                            0
                          ],
              ...
              
              The thing is that I need to delete the last two characters in the square brackets the "," and the "0", so it must seem like:
              
              [
                            -90.67575919025678,
                            14.12140539076991
                          ],
                          [
                            -90.67691295444409,
                            14.11436171657998
                          ],
              

              you have to embed it between two lines of ``` (tripple backticks) otherwise your code gets stripped.

              best regards.

              A 1 Reply Last reply May 7, 2019, 12:29 PM Reply Quote 1
              • B
                Billy Martin
                last edited by May 6, 2019, 9:06 PM

                Hi… Thanks… I’ve tried that in a new document and worked either. But in the original files the strings starts after three tab spaces… how can I add them into the search expression to match the string? is there any tab char I can add or how to add the 15 blank spaces between?

                        [
                          -90.89344601114183,
                          14.26720713414475,
                          0
                        ],
                        [
                          -90.89410910416692,
                          14.2672050050027,
                          0
                        ],
                        [
                          -90.89397902924168,
                          14.26244600987243,
                          0
                        ]
                
                1 Reply Last reply Reply Quote 2
                • P
                  PeterJones
                  last edited by May 6, 2019, 9:55 PM

                  @Billy-Martin ,

                  I believe you should be able to update your find to: ,\R\h*0\R(?=\h*\]). The \h* adds a match of 0 or more horizontal spaces (space or tab).

                  Actually, given your original spec, saying the closing ] should be on a separate line, I would actually say

                  • ,\R\h*0(?=\R\h*\])
                    (which moves the newline after the 0 to not be deleted)

                  For me, this converts

                          [
                            -90.89344601114183,
                            14.26720713414475,
                            0
                          ],
                          [
                            -90.89410910416692,
                            14.2672050050027,
                            0
                          ],
                          [
                            -90.89397902924168,
                            14.26244600987243,
                            0
                          ]
                  

                  to

                          [
                            -90.89344601114183,
                            14.26720713414475
                          ],
                          [
                            -90.89410910416692,
                            14.2672050050027
                          ],
                          [
                            -90.89397902924168,
                            14.26244600987243
                          ]
                  
                  1 Reply Last reply Reply Quote 2
                  • G
                    guy038
                    last edited by guy038 May 6, 2019, 10:25 PM May 6, 2019, 10:25 PM

                    Hello @billy-martin, @peterjones and All,

                    Ah ! Nice, Peter, I was about to post a solution, but you beat me to it ;-))

                    And, of course, our solutions are identical

                    SEARCH ,\R\h*0(?=\R\h*\],)

                    REPLACE Leave EMPTY

                    So, I just give some explanations to Billy, on this regex S/R :

                    • The \R syntax represents any form of line-break ( \r\n for Windows files, \n for Unix files and \r for Mac files )

                    • The \h* part matches any range, even null, of horizontal blank characters, i.e. space, tabulation and no-breaking space character, of respective Unicode values \x{0020}, \x{0009} and \x{00A0 )

                    • The character [, being a regex meta-character, must be escaped with the \ character, to be interpreted as a literal

                    • So, the search regex looks for a comma, followed with a line-break, then some possible blank chars and, finally, a zero

                    • But ONLY IF the look-ahead structure (?=\R\h*\],) is true i. e. if the zero digit is immediately followed with a line-break, then possible blank characters and, finally, the string ],

                    • As the replace zone is empty, the search match ,\R\h*0, described above, is simply deleted

                    Best Regards

                    guy038

                    1 Reply Last reply Reply Quote 3
                    • P
                      PeterJones
                      last edited by May 6, 2019, 10:29 PM

                      This has nothing to do with the main topic. Sorry for the tangent, but I’m curious:

                      @Meta-Chuh said:

                      @Billy-Martin,
                      your original text is:

                      Meta, how do you see what the original text was? In some other forums, I am able to view the source of the post, and that shows the pre-edited version… but I when I view the source in the Notepad++ Community forum, I don’t see anything with the spaces. Where did you get the original from?

                      1 Reply Last reply Reply Quote 2
                      • B
                        Billy Martin
                        last edited by May 6, 2019, 11:20 PM

                        Thank you guys… it worked as expected and as desired.

                        Thanks a lot… it really helps me a lot and makes my life easier.

                        Best regards,

                        Billy

                        1 Reply Last reply Reply Quote 2
                        • A
                          Alan Kilborn @Meta Chuh
                          last edited by May 7, 2019, 12:29 PM

                          @PeterJones said:

                          Meta, how do you see what the original text was?

                          @Meta-Chuh YEA! How about it Meta??

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