Community
    • Login

    Regex - find occurence of 2 consecutive lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    11 Posts 7 Posters 1.3k 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.
    • Fernando Avendaño217F
      Fernando Avendaño217
      last edited by

      Hi!
      I’m a real newbee to regex :)

      I’ve been trying to select and replace all the occurences of 2 consecutive lines, the first line contains the text:
      Checking
      and the one right below contains the text:
      Failed qualification

      I want to select them and replace them if they are right next to each others, not otherwise as there are many occurences in the file and I dont want other lines to be selected and replaced.

      I get it working in https://regex101.com/ with the following:
      (^<FLTR>.Checking.[\n,\r])(^<FLTR>.Failed qualification.)
      but the same regex is not working in Notepad++ v 7.7.1

      Any help would be greatly appreciated!

      Sample of the text I need to replace lines in:
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > / Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:17> Checking “ASI:SHR:SandboxCallReconEngine_999_ContractAssoc`!” (899)
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Failed qualification
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > /
      Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:18> Checking “SHR:SHR:FINUpdateGroupList” (900)
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Failed qualification
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > /
      Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:19> Checking “ASI:SHR:All_SetMarkAsDelete_No” (980)
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Passed – perform actions
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 0 : Push Fields -> “BMC.CORE:BMC_BaseElement”
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > <deferred to phase 2>
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 1 : Set Fields
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > Mark As Deleted (400129100) = 0
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > /
      Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:20> Checking “ASI:SHR:All_SetMarkAsDelete_Yes” (980)
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Failed qualification

      Only this should be left:
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > / Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:19> Checking “ASI:SHR:All_SetMarkAsDelete_No” (980)
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Passed – perform actions
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 0 : Push Fields -> “BMC.CORE:BMC_BaseElement”
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > <deferred to phase 2>
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 1 : Set Fields
      <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > Mark As Deleted (400129100) = 0

      EkopalypseE Alan KilbornA 2 Replies Last reply Reply Quote 0
      • EkopalypseE
        Ekopalypse @Fernando Avendaño217
        last edited by

        @Fernando-Avendaño217

        not an regex answer but are you aware that this is an builtin feature?
        Edit->Line operations->remove consecutive duplicate lines

        Fernando Avendaño217F 1 Reply Last reply Reply Quote 1
        • rinku singhR
          rinku singh
          last edited by rinku singh

          @Fernando-Avendaño217 said:

          Any help would be greatly appreciated!

          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > / Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:17> Checking “ASI:SHR:SandboxCallReconEngine_999_ContractAssoc`!” (899)
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Failed qualification
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > / Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:18> Checking “SHR:SHR:FINUpdateGroupList” (900)
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Failed qualification
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > / Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:19> Checking “ASI:SHR:All_SetMarkAsDelete_No” (980)
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Passed – perform actions
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 0 : Push Fields -> “BMC.CORE:BMC_BaseElement”
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > <deferred to phase 2>
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 1 : Set Fields
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > Mark As Deleted (400129100) = 0
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > / Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:20> Checking “ASI:SHR:All_SetMarkAsDelete_Yes” (980)
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Failed qualification
          
          Only this should be left:
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > / Wed Sep 11 2019 10:25:16.0900 / <Filter Level:0 Number Of Filters:19> Checking “ASI:SHR:All_SetMarkAsDelete_No” (980)
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > --> Passed – perform actions
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 0 : Push Fields -> “BMC.CORE:BMC_BaseElement”
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > <deferred to phase 2>
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > 1 : Set Fields
          <FLTR> <TID: 0000000310> <RPC ID: 0008023240> <Queue: Fast > <Client-RPC: 390620 > <USER: XXXXXXX > <Overlay-Group: 1 > Mark As Deleted (400129100) = 0
          

          but it open in notepad & have no consecutive lines

          1 Reply Last reply Reply Quote 0
          • Fernando Avendaño217F
            Fernando Avendaño217 @Ekopalypse
            last edited by

            @Ekopalypse but the lines are not duplicated…

            1 Reply Last reply Reply Quote 0
            • Michael VincentM
              Michael Vincent
              last edited by

              @Fernando-Avendaño217

              To use the Edit->Line operations->remove consecutive duplicate lines approach, you’ll need to sort the lines first.

              1 Reply Last reply Reply Quote 1
              • rinku singhR
                rinku singh
                last edited by

                @Fernando-Avendaño217 said:

                ^<FLTR>.Checking.[\n,\r])(^<FLTR>.Failed qualification

                ^<FLTR>.*Checking.*$\r\n^<FLTR>.*Failed qualification$ it find 3 lines

                • 1
                • 3
                • 11
                1 Reply Last reply Reply Quote 1
                • rinku singhR
                  rinku singh
                  last edited by

                  @Fernando-Avendaño217 said:

                  Only this should be left:

                  i was skip this statement regex is working 100%

                  ^<FLTR>.*Checking.*$\r\n^<FLTR>.*Failed qualification$

                  1 Reply Last reply Reply Quote 1
                  • Alan KilbornA
                    Alan Kilborn @Fernando Avendaño217
                    last edited by Alan Kilborn

                    This post is deleted!
                    1 Reply Last reply Reply Quote 1
                    • Fernando Avendaño217F
                      Fernando Avendaño217
                      last edited by

                      This one finally solved my problem, thank you all for the input!

                      .Checking.$\R(.Failed qualification$|.– filter is ignored$)

                      1 Reply Last reply Reply Quote 1
                      • Allen BaiA
                        Allen Bai
                        last edited by

                        .+Checking.+\r\n.+Failed qualification+

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

                          Hello, @fernando-avendaño217 and All,

                          I was away from the N++ community, since more than a month ( see my post below )

                          https://community.notepad-plus-plus.org/post/47895

                          So, Fernando, my reply is quite out of date. However, just for info, here is my solution :

                          SEARCH (?-is)^.+\bChecking\b.*\R.+\bFailed qualification\R

                          REPLACE Leave EMPTY

                          Notes :

                          • First the part (?-is) are in-line modifiers which implies :

                            • The search is processed in a non-insensitive way ( -i )

                            • The regex dot char ( . ) match a single standard character and not any EOF char ( -s )

                          • Then the part ^.+\bChecking\b.*\R looks for an entire line containing the word Checking, with that exact case

                          • Finally the part .+\bFailed qualification\R grabs any entire next line, which contains the exact expression Failed qualification, with that exact case

                          • As replacement is empty, these two consecutive entire lines are simply deleted :-))

                          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