I have text on new lines like so:
tom
tim
john
will
tod
hello
test
ttt
three
I want to delete every third line so using the example above I want to remove: john,hello,three
I know this calls for some regex, but I am not the best with it!
What I tried:
Search: ([^\n]*\n?){3} //3 in my head to remove every third
Replace: $1
The others I tried were just attempts with \n\r
etc. Again, not the best with regex. The above attempt I thought was kinda close.
This will delete every third line that may contain more than one word.
(?:[^\r\n]+\R){2}\K[^\r\n]+(?:\R|\z)
LEAVE EMPTY
Explanation:
(?: # start non capture group
[^\r\n]+ # 1 or more non linebreak
\R # any kind of linebreak (i.e. \r, \n, \r\n)
){2} # end group, appears twice (i.e. 2 lines)
\K # forget all we have seen until this position
[^\r\n]+ # 1 or more non linebreak
(?: # start non capture group
\R # any kind of linebreak (i.e. \r, \n, \r\n)
| # OR
\z # end of file
) #end group
Result for given example:
tom
tim
will
tod
test
ttt
Screen capture:
Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With