Community
    • Login

    Need help in replace and delete all similar sentence

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    4 Posts 4 Posters 245 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.
    • TOMMY TANT
      TOMMY TAN
      last edited by

      Need help on how to replace and delete all this particular sentence only in my notepad.

      i have near to 100+ ‘‘VRDP4-XXXXXXXXXXX’’

      SM1+VRDP4-OOCU4868933:20240906151200:;;::KOJ’
      SM1+VRDP4 OOCU7704147:20240905132700:;;::KOJ’
      SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’

      Lycan ThropeL mkupperM 2 Replies Last reply Reply Quote 0
      • Lycan ThropeL
        Lycan Thrope @TOMMY TAN
        last edited by

        @TOMMY-TAN
        Anybody that can help you, will need more details of what you are asking. I suggest the links below to start.
        https://community.notepad-plus-plus.org/topic/15739/faq-request-for-help-without-sufficient-information-to-help-you
        https://community.notepad-plus-plus.org/topic/21925/faq-formatting-forum-posts
        https://community.notepad-plus-plus.org/topic/15765/faq-where-to-find-regular-expressions-regex-documentation

        1 Reply Last reply Reply Quote 1
        • mkupperM
          mkupper @TOMMY TAN
          last edited by mkupper

          @TOMMY-TAN, I’ll take a guess at what you want.

          Using Notepad++'s Regular Expression mode then do a search/replace using:

          Search: (?-i)(?<=^SM1\+)VRDP4-[A-Z]{4}[0-9]{7}(?=:202[0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9]00:;;::KOJ’$)
          Replace: (leave this blank or empty)

          The search thing has four main parts:

          • (?-i) Tells Notepad++ to turn the “ignore case” flag off so that things such as VRDP in the pattern only match an upper case VRDP in the data.
          • (?<=^SM1\+) matches the stuff before the VRDP4-… thing you want to delete or replace.
          • VRDP4-[A-Z]{4}[0-9]{7} matches the VRDP4-… thing. I made the assumption that it has four letters followed by seven digits. You should be able to figure out how to make the adjustments should VRDP4-… thing not always be four letters followed by seven digits. I noticed that your second line of the example data was missing the hyphen or dash between VRDP4 and the rest of the thing. If your data sometimes has a space and other times has a hyphen or dash then use VRDP4[ -]... instead of VRDP4-
          • (?=:20[0-9][0-9][01][0-9][0-3][0-9][012][0-9][0-5][0-9]00:;;::KOJ’$) is overkill but it matches the stuff after the VRDP4- thing. I saw that the first part looked like a date/time formatted as YYYYMMDDHH with zeros for the seconds and so set up the pattern to match the years 2000 to 2099. If the seconds are not always zero then you can use [0-5][0-9] instead of 00.

          You can test this from the Mark tab the Search/replace dialog box. Just do a Mark-All and the stuff that gets highlighted will be the matches and will be the data that gets deleted should you do a replace-all on the search/replace tab.

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

            Hello @tommy-tan, @lycan-thrope, @mark-olson and All,

            Given the INPUT text, below

            SM1+VRDP4-OOCU4868933:20240906151200:;;::KOJ’
            SM1+VRDP4 OOCU7704147:20240905132700:;;::KOJ’
            SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’
            DEF456SM1+VRDP4-CBHU4477056:20240906141100:;;::KOJ’
            AB9+VRDP4-CBHU4477056:20240906141100:;;::KOJ’
            

            A more simple formulation would be to use one of the three regexes, below :

            • (?-is)VRDP4.+?(?=:) which matches any string beginning by an uppercase string VRDP4 till the very first colon of the current line

            • (?-is)(?<=^SM1\+)VRDP4.+?(?=:) if, in addition, the uppercase string VRDP4 is preceded by an uppercase string SM1+, strictely beginning a line

            • (?-is)(?<=SM1\+)VRDP4.+?(?=:) if, in addition, the uppercase string VRDP4 is just preceded by an uppercase string SM1+


            Now , if we consider the general example below :

            ABC
            XYZ
            123ABC
            XYZ
            ABCXYZ
            123ABCXYZ
            

            As said above :

            • The regex (?-i)(?<=^ABC)XYZ would find any uppercase string XYZ if predeced by an uppercase string ABC strictely beginning a line

            • The regex (?-i)(?<=ABC)XYZ would find any uppercase string XYZ, if preceded by an uppercase string ABC

            However the two regexes (?-i)^(?<=ABC)XYZ or (?-i)(?<=ABC)^XYZ cannot find any match ! Why ? Just because the ^ is a regex assertion which is a shorthand of the (?<=\n|\r) syntax. Thus, these two syntaxes can be replaced by (?-i)(?<=\n|\r)(?<=ABC)XYZ and (?-i)(?<=ABC)(?<=\n|\r)XYZ. And it obvious that the string XYZ CANNOT be preceded, at the same time, with both an EOL character and the string ABC !

            For people who want to know the right syntaxes, in this specific case, they are (?s-i)^(?<=ABC..)XYZ and (?s-i)(?<=ABC..)^XYZ, where the two dots represent an EOL char ! So, they both match an uppercase string XYZ, right after an uppercase string ABC\r\n

            Note that the third syntax (?s-i)(?<=ABC..)XYZ, without any ^ symbol, matches also the two uppercase strings XYZ, beginning a line


            Actually, to be exhaustive, the later regex (?s-i)(?<=ABC..)XYZ matches any uppercase string XYZ, preceded by a fixed string of 5 characters :

            • The first three are the uppercase string ABC

            • The following two chars can be absolutely any char ( standard or EOL characters )

            Best Regards,

            guy038

            1 Reply Last reply Reply Quote 2
            • First post
              Last post
            The Community of users of the Notepad++ text editor.
            Powered by NodeBB | Contributors