Regex - find occurence of 2 consecutive lines
-
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 qualificationI 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.1Any 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 qualificationOnly 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 -
not an regex answer but are you aware that this is an builtin feature?
Edit->Line operations->remove consecutive duplicate lines -
@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) = 0but it open in notepad & have no consecutive lines
-
@Ekopalypse but the lines are not duplicated…
-
To use the Edit->Line operations->remove consecutive duplicate lines approach, you’ll need to sort the lines first.
-
@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
-
@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$ -
This post is deleted! -
This one finally solved my problem, thank you all for the input!
.Checking.$\R(.Failed qualification$|.– filter is ignored$)
-
.+Checking.+\r\n.+Failed qualification+
-
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\RREPLACE
Leave EMPTYNotes :
-
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.*\Rlooks for an entire line containing the wordChecking, with that exact case -
Finally the part
.+\bFailed qualification\Rgrabs any entire next line, which contains the exact expressionFailed qualification, with that exact case -
As replacement is empty, these two consecutive entire lines are simply deleted :-))
Best Regards,
guy038
-
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