Community
    • Login

    I want to remove certain range. Please help me

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    10 Posts 4 Posters 2.6k Views 3 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.
    • JohnnychangprogrammerJ Offline
      Johnnychangprogrammer
      last edited by

      Hi Everyone!

      I want to remove certain range.

      I have a lot of files.

      The examples are below.

      Line 146 of tommy.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>123456-7890123</td>
      Line 146 of jimmy.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>163456-7875865</td>
      Line 146 of michael.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>164689-8965698</td>
      Line 146 of kimberly.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>748956-8971457</td>
      .
      .
      .
      .
      .

      So I want to change 13 digit numbers to 7 digit numbers.

      Line 146 of tommy.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>123456-7******</td>
      Line 146 of jimmy.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>163456-7******</td>
      Line 146 of michael.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>164689-8******</td>
      Line 146 of kimberly.html: <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”>748956-8******</td>
      .
      .
      .
      .
      .

      Have a good day!

      Claudia FrankC Scott SumnerS 2 Replies Last reply Reply Quote 2
      • Claudia FrankC Offline
        Claudia Frank @Johnnychangprogrammer
        last edited by

        @Johnnychangprogrammer

        Some questions to clarify the real data.
        Is it always line 146? In each of the files?
        Is always <td width=“150” id=“content_1” style=“background-color:#F0FCFF;”> in front of the 13 digit number?
        You wrote you want to have 7 digits but your example shows 7 digits and 6 times asteriks.
        Which version do you want to have?

        If the layout is not consistent, is the 13 digit number unique?

        Cheers
        Claudia

        JohnnychangprogrammerJ 1 Reply Last reply Reply Quote 2
        • Scott SumnerS Offline
          Scott Sumner @Johnnychangprogrammer
          last edited by

          @Johnnychangprogrammer

          One way might be:

          Find what zone: (?<=\d{6}-\d)\d{6}(?=</td>$)
          Replace with zone: ******
          Search mode: Regular expression

          JohnnychangprogrammerJ 1 Reply Last reply Reply Quote 2
          • JohnnychangprogrammerJ Offline
            Johnnychangprogrammer @Claudia Frank
            last edited by

            @Claudia-Frank

            Yes. It is always in line 146 each of the files.

            1 Reply Last reply Reply Quote 0
            • JohnnychangprogrammerJ Offline
              Johnnychangprogrammer @Scott Sumner
              last edited by

              @Scott-Sumner

              Thanks. That’s great !

              But other lines are also replaced.

              I want to change the exact lines.

              Scott SumnerS 1 Reply Last reply Reply Quote 0
              • Scott SumnerS Offline
                Scott Sumner @Johnnychangprogrammer
                last edited by

                @Johnnychangprogrammer

                Ah, I missed the “line 146” requirement the first time around…I thought it was part of the data, I suppose!

                Maybe this:

                FInd what zone: (?-s)((?:^.*\R){145}.*?-\d)\d{6}(?s)(</td>$.*)
                Replace with zone: \1******\2

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

                  Hi, @johnnychangprogrammer, @scott-sumner, @claudia-frank and All,

                  UPDATE :

                  Do not trust in the two regex S/R, related in this post and refer to my second post, and to Scott explanations, below !


                  Scott, I think that we can, also, use the shortened regex S/R, below :

                  SEARCH (?-s)((?:^.*\R){145}.*?-\d)\d{6}

                  REPLACE \1******

                  Because, as the remaining of file, after line 146, must be preserved, the best way to do is to ignore all that part, isn’t it ?


                  @johnnychangprogrammer, as you will use the Find in Files dialog, which scan every file from beginning to end, performing a Replace All operation, you could, as well, use the third version, below :

                  SEARCH (?-s)(?:^.*\R){145}.*?-\d\K\d{6}

                  REPLACE ******

                  In case, you would use the Replace dialog, instead, with that third version, you should :

                  • Tick the Wrap around option

                  • Click, exclusively, on the Replace All button ( not the step by step Replace button )

                  Cheers,

                  guy038

                  Scott SumnerS 1 Reply Last reply Reply Quote 2
                  • Scott SumnerS Offline
                    Scott Sumner @guy038
                    last edited by

                    @guy038 said:

                    the remaining of file, after line 146, must be preserved, the best way to do is to ignore all that part

                    Hi Guy,

                    The reason I used .* near the end of my regex was to protect against the possible case where the file is a lot longer than 146 lines and has matches farther on down in the file. Remember that when N++ finds/replaces a match, it starts looking again at the character position following the match/replacement–for more matches. Your first SEARCH suggestion fails in that regard–meaning that matches past line 146 will be changed, and this didn’t seem to be what the OP wanted.

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

                      Hello, Hi, @johnnychangprogrammer, @scott-sumner, @claudia-frank and All,

                      Ah, Scott, very clever, indeed ! My fault was to test my regexes, against a 200 lines text which doesn’t allow a second match, anyway :-((

                      So, obviously, my regexes are not reliable, in @johnnychangprogrammer’s case, and the Scott regex S/R is the unique correct solution !

                      Best Regards,

                      guy038

                      Scott SumnerS 1 Reply Last reply Reply Quote 3
                      • Scott SumnerS Offline
                        Scott Sumner @guy038
                        last edited by Scott Sumner

                        @guy038

                        HAha…I tested with {2} in place of {145}…much less work to create test data that way…I just changed it to 145 for posting!

                        :-D

                        Of course, if we could ever get the \A to work… :-(

                        1 Reply Last reply Reply Quote 3

                        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