5

Well, I guess that that is my title is pretty much self explanatory on what I'm about to achieve.

Here is an example of my current text file:

"Diva" was the winning song of the Eurovision Song Contest 1998.
Who will win Eurovision Song Contest 2015?
Eurovision Song Contest Statistics:
Who will win Eurovision 2015?

This is what I want to get:

"Diva" was the winning song of the Eurovision Song Contest 1998.
Eurovision Song Contest Statistics:

So basically each line that contains the ? character (the location doesn't necessarily have to be at the end of the line) will be replaced with nothing.

I have tried [^\r\n]*?[^\r\n]*([\r\n]+|$) but it removes too much.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Hezi-Gangina
  • 637
  • 6
  • 20

4 Answers4

3
^[^\n]*\?[^\n]*(?:\n|$)

Try this.Replace by empty string.See demo.

https://regex101.com/r/sJ9gM7/76

vks
  • 67,027
  • 10
  • 91
  • 124
2

You can use [^\r\n]*\?[^\r\n]*([\r\n]+|$) regex to match a line having a ? symbol. Mark . matches newline.

Replace with empty string.

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Opps... This was exactly what I was doing I just forgot the backslash \? Thank you very much ! :) – Hezi-Gangina Apr 09 '15 at 12:10
  • @Hezi-Gangina: You are welcome. `?` is a special character in regexes, and must be escaped when you search for a literal `?`. Just in case you are interested, here is some more information on what needs to be escaped: http://stackoverflow.com/questions/399078/what-special-characters-must-be-escaped-in-regular-expressions. – Wiktor Stribiżew Apr 09 '15 at 12:11
  • I also added to the question that detail that you tried a regex with unescaped question mark. It's important. – Wiktor Stribiżew Apr 09 '15 at 12:20
2

In order to deal with any linebreak:

Find what: ^.*\?.*(\R|$)
Replace with: <NOTHING>

\R stands for any line break, ie. \r, \n and \r\n

Make sure that Regular Expression is checked and dot matches newline is NOT.

Toto
  • 89,455
  • 62
  • 89
  • 125
2

You can avoid regular expressions and use the Mark tab of the Find window. Select Search mode as Normal, also select Bookmark line. Set the Find what to be ? and then click Mark all. Next use the menu => Search => Bookmarks => Remove bookmarked lines.

AdrianHHH
  • 13,492
  • 16
  • 50
  • 87