Regular Expressions - How to Delete Two Lines, If one contains X?

TheWicker

Senior Member
Joined
May 15, 2008
Messages
810
Reaction score
270
So I have a file and need to delete all instances that contain a certain string in the first line. Also Each line below the line that contains that string should also be completely deleted (no matter what it is). How do I make this happen?

Now obviously the expression for finding that first line is:

^.*STRING.*$

After that I'm stuck.

In other words I need to delete TWO lines and the first line contains my string.
 
Try:

Code:
^.*STRING.*\r?\n.*$

Windows uses \r\n for newlines, so make \r optional just in case. :)
 
Doen't seem to work. Let me give you an example of what I'm trying to achieve. I have some text like this one:

Code:
http://www.esportbike.com/forums/showthread.php?t=142594
Superbike Toy Store<||>Shoei X 11 Kaama
http://www.esportbike.com/forums/showthread.php?t=142484
Superbike Toy Store<||>Sale on Arlen Ness Deep Freeze Suit
http://forums.nba-live.com/viewtopic.php?f=76&t=51294
[B]Entertainment Media<||>Flight of the Conchords[/B]

I am trying to highlight this phrase "Entertainment Media<||>Flight of the Conchords". Now I want to achieve this with typing ^.*forums.nba-live.com.*\r?\n.*$ (if it worked properly). Hence selecting the line that is below the line that contains the forums.nba-live.com url.
 
Your first post says you want to delete the matching line and the line under it, but your second post implies you're trying to match and extract the second line. Which is it?

The regex I gave you does indeed match both lines: http://rubular.com/r/CW03tUa6qP

If you want to capture each line within the regex, try this: http://rubular.com/r/3scdMug8as
 
Back
Top