REGEX: Mark/Delete the 2 second line after some word
-
hello everyone. I need to mark/delete the 2 second line after some word. For exemple:
1.line
2.line
3.bla bla bla WORD_1 bla bla
4.line
5.line
6.line ETCSo, I want to delete the line that contains WORD_1 and the next 2 lines (but without line 6). Can anyone help me?
I try this regex, this will delete the line with WORD_1, but will not delete line 4 and 5. But will insert another line 4 instead delete.
Search:
^.*WORD_1.*$
Replace by:
\n\n -
Hello, Vasile,
Not difficult, indeed !
The general regex S/R, which deletes ANY line, containing a SPECIFIC word, with generic name = WORD, along with the N lines, following this line, is :
SEARCH
(?-s)^.*WORD.*\R(.*\R){N}REPLACE
EMPTYSo, in your case, the search regex should be
(?-s)^.*WORD_1.*\R(.*\R){2}
In the same way, the general regex S/R, below, which would delete ANY line, containing the word WORD and the N lines located BEFORE this line, is :
SEARCH
(?-s)(.*\R){N}.*WORD.*\RREPLACE
EMPTY
Notes :
-
Due to the
(?-s)modifier, the dot,., stands for a single standard character, only -
As usual, the
\Rsyntax matches any kind of Line Break (\r\nin Windows files,\nin Unix files or\rin old Mac files ) -
The part
.*\Rrepresents a complete line, even empty, with its EOL character(s) -
So the syntax
(.*\R){N}, where N is an integer, stands N complete lines
Best Regards
guy038
-
-
well, guy38, nice present for me.
thanks a lot !
This is for you !
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