Notepad++:: Completely remove lines that contains question mark via Regex

拈花ヽ惹草 提交于 2019-12-23 12:00:52

问题


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.


回答1:


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

Try this.Replace by empty string.See demo.

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




回答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.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/29537982/notepad-completely-remove-lines-that-contains-question-mark-via-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!