I want to remove certain range. Please help me



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



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



  • @Johnnychangprogrammer

    One way might be:

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



  • @Claudia-Frank

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



  • @Scott-Sumner

    Thanks. That’s great !

    But other lines are also replaced.

    I want to change the exact lines.



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



  • 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



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



  • 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



  • @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… :-(


Log in to reply