RegEx 使用 Notepad++ 排除行

标签 regex notepad++

这个问题在这里已经有了答案:




9年前关闭。




Possible Duplicate:
notepad++ Inverse Regex replace (all but string)



假设我有以下...
http://whateverurl.com/is-not-wanted-but-it-is-here-anyway
http://icantbelieveibeenonthisallday.com/i-want-to-shoot-myself
http://hereiswhatireallywant.net/hey-there-sweet-thang
http://howsithangingloser.org/i-hope-someone-helps-you
http://heresanotherbeauty.net/that-i-want-to-be-all-up-in

我只想找到不包含“.net/”的行,这样我就可以什么都不用替换它,因此删除。

我在网上和这个网站上搜索,找到了 (?!xxx) 字符串,
所以我试图做 (?!.net/)
但似乎 Notepad++ 不支持该字符串
或者我可能用错了,因为我是 RegEx 的新手。

谁能告诉我如何在 Notepad++ 中找到排除特定字符串的行?

最佳答案

据我所知,Notepad++ 的正则表达式支持不允许您实际捕获换行符。你最好使用这个正则表达式:

^.*\.net.*$

用空替换它(现在它是一个空行),然后将搜索模式更改为扩展并替换 \r\n\r\n\r\n (或 \n\n\n 如果使用 Unix 样式的行结尾)。

BoltClock 指出我落后于时代,版本 6 支持这一点。您可以使用此正则表达式来查找这些行并删除它们:
^.*\.net.*(\r\n|$)

编辑 :

I appreciate your response, but you misunderstood what I said. I'm trying to find lines that DO NOT CONTAIN the .net/ to delete them. Can it be done?



哎呀。如果要匹配没有 .net 的行在它们中,使用这个表达式:
^(?!.*?\.net/).*\r\n

适用于 Notepad++ 6。

关于RegEx 使用 Notepad++ 排除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10711041/

相关文章:

editor - 如何将 Notepad++ 配置为退格缩进

正则表达式搜索并替换为条件 : works in Notepad++, 不在 Powergrep 中?

java - 匹配完整异常名称的正则表达式

javascript - 使用正则 exp 对货币进行四舍五入

javascript - 为什么这个正则表达式会返回前面的字符?

Javascript 正则表达式 多个小数

regex - 在 BASH 中,删除两组字符之间的所有内容

正则表达式将选项值复制到 select 中的文本中

duplicates - 在 Notepad++ 中删除重复行

regex - 无法在 Notepad++ 正则表达式搜索和替换中引用捕获组