I need to delete two characters in two continuous lines



  • 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



  • @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.



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



  • @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.



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



  • @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.



  • 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
            ]


  • @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
            ]
    


  • 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



  • 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?



  • 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



  • @PeterJones said:

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

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


Log in to reply