简体   繁体   English

Notepad ++ ::通过Regex完全删除包含问号的行

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

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. 我试过[^\\r\\n]*?[^\\r\\n]*([\\r\\n]+|$)但它删除了太多。

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

Try this.Replace by empty string .See demo. 试试这个。 empty string 。请看演示。

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

You can use [^\\r\\n]*\\?[^\\r\\n]*([\\r\\n]+|$) regex to match a line having a ? 您可以使用[^\\r\\n]*\\?[^\\r\\n]*([\\r\\n]+|$)正则表达式来匹配一个有?的行? symbol. 符号。 Mark . matches newline 马克. matches newline . matches newline . . matches newline

Replace with empty string. 替换为空字符串。

在此输入图像描述

In order to deal with any linebreak: 为了处理任何换行:

Find what: ^.*\\?.*(\\R|$) 找到: ^.*\\?.*(\\R|$)
Replace with: <NOTHING> 替换为: <NOTHING>

\\R stands for any line break, ie. \\R代表任何换行符,即。 \\r , \\n and \\r\\n \\r\\n\\r\\n

Make sure that Regular Expression is checked and dot matches newline is NOT. 确保选中Regular Expression并且dot matches newline不是。

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 . 接下来使用菜单=> 搜索 => 书签 => 删除书签行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM