• Login
Community
  • Login

I want to remove certain range. Please help me

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
10 Posts 4 Posters 1.9k 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.
  • J
    Johnnychangprogrammer
    last edited by May 18, 2018, 12:04 PM

    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!

    C S 2 Replies Last reply May 18, 2018, 12:21 PM Reply Quote 2
    • C
      Claudia Frank @Johnnychangprogrammer
      last edited by May 18, 2018, 12:21 PM

      @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

      J 1 Reply Last reply May 20, 2018, 10:38 PM Reply Quote 2
      • S
        Scott Sumner @Johnnychangprogrammer
        last edited by May 18, 2018, 12:23 PM

        @Johnnychangprogrammer

        One way might be:

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

        J 1 Reply Last reply May 20, 2018, 10:41 PM Reply Quote 2
        • J
          Johnnychangprogrammer @Claudia Frank
          last edited by May 20, 2018, 10:38 PM

          @Claudia-Frank

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

          1 Reply Last reply Reply Quote 0
          • J
            Johnnychangprogrammer @Scott Sumner
            last edited by May 20, 2018, 10:41 PM

            @Scott-Sumner

            Thanks. That’s great !

            But other lines are also replaced.

            I want to change the exact lines.

            S 1 Reply Last reply May 21, 2018, 12:55 AM Reply Quote 0
            • S
              Scott Sumner @Johnnychangprogrammer
              last edited by May 21, 2018, 12:55 AM

              @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
              • G
                guy038
                last edited by guy038 May 21, 2018, 1:05 PM May 21, 2018, 11:24 AM

                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

                S 1 Reply Last reply May 21, 2018, 12:09 PM Reply Quote 2
                • S
                  Scott Sumner @guy038
                  last edited by May 21, 2018, 12:09 PM

                  @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
                  • G
                    guy038
                    last edited by May 21, 2018, 12:27 PM

                    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

                    S 1 Reply Last reply May 21, 2018, 12:32 PM Reply Quote 3
                    • S
                      Scott Sumner @guy038
                      last edited by Scott Sumner May 21, 2018, 12:33 PM May 21, 2018, 12:32 PM

                      @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
                      4 out of 10
                      • First post
                        4/10
                        Last post
                      The Community of users of the Notepad++ text editor.
                      Powered by NodeBB | Contributors