notepad++ - 使用 Notepad++ 提取基于单行文本的特定文本行
问题描述
我在一个巨大的文本文件中有下面的行,并且想要提取 LineD 和它前面的其他行。如果该集合不包含 D 行,则应忽略该集合
LineA
LineB
LineC
Line1
Line2
Line3
LineD
Linex
LineY
LineZ
Line4
Line5
Line6
LineD
输出应该是
Line1
Line2
Line3
LineD
Line4
Line5
Line6
LineD
解决方案
- Ctrl+H
- 找什么:
(?:\A|\R\R)(?:(?!LineD)[\s\S])*?(?=\R\R|\z)
- 用。。。来代替:
LEAVE EMPTY
- 检查 火柴盒
- 检查 环绕
- CHECK 正则表达式
- 取消选中
. matches newline
- Replace all
解释:
(?:\A|\R\R) # non capture group, beginning of file OR 2 linebreaks
(?: # non capture group
(?!LineD) # negative lookahead, make sure sure we haven't "LineD"
[\s\S] # any character, including linebreak
)*? # end group, may appear 0 or more times, not greedy
(?=\R\R|\z) # positive lookahead, make sure we have a double linebreak OR end of file after.
截图(之前):
截图(之后):
推荐阅读
- r - 每当我在 R 中为 Sankey 调用 colourScale 时,它都不会输出图表
- angular - Nx/Angular 项目的 Esslint 配置(无主机元数据属性)
- rust - 为什么 println!(foo.bar()?) 移动 foo?
- openapi - 如何在 OpenAPI 规范中内联示例字段?
- iis - 是否可以以登录用户身份运行 IIS 站点?
- jquery - 非常简单的 jQuery 秒倒计时
- qt - 仅从 C++ API 进行异步调用,Qt 网络通道迁移看起来是不可能的
- python - 如何在浏览器不登录 Google 的情况下向 Google 授权
- pine-script - 如何将前一天的价值区域高低(如会话(每日/每周/等)交易量曲线)绘制为水平?
- python - 如何在 Python 中从 .env 获取和设置环境变量?