regex - 只返回不包含特定单词的行
问题描述
我有这段文字
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/Documents/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading page WebParts...
2/27/2020 7:00:44 PM 138 (6036) Downloading page web parts completed. 1 web parts successfully downloaded.
2/27/2020 7:00:44 PM 138 (6036) Downloading page content...
2/27/2020 7:00:44 PM 138 (6036) Restarting from position 8312...
2/27/2020 7:00:44 PM 138 (6036) Error: error
double double
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/sdadasda/Forms/All.aspx...
2/27/2020 7:00:44 PM 138 (6036) Error: Unspecified error
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/21312332131/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/Documeents/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/wr/Forms/All.aspx...
我需要返回所有行:
- “下载查看页面:”部分在其中
- 其中没有“文件”一词。
预期结果:
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/21312332131/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/123/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/Documeents/Forms/All.aspx...
2/27/2020 7:00:43 PM 138 (6036) Downloading view page: /personal/test/wr/Forms/All.aspx...
我尝试了负前瞻和常规 [^Docuemnts]。似乎没有一个工作。
(\(\d+\)).*Downloading view page:\s\/personal\/\S+\/[^(Documents)]\/F
(\(\d+\)).*Downloading view page:\s\/personal\/\S+\/(?!Documents)\/F
解决方案
一个简单的解决方案是只使用一个否定的前瞻来排除Documents
:
^(?!.*\bDocuments\b).*\bDownloading view page:(?!\S).*$
演示
以下是正则表达式模式的完整解释:
^ from the start of the string
(?!.*\bDocuments\b) assert that "Documents" does not occur anywhere in the line
.*\bDownloading view page: then match "Downloading view page:"
(?!\S) assert that what follows is either whitespace or end of string
.* match the rest of the line
$ until the end of the string
推荐阅读
- r - Tableau 中的保留错误。异常:外部服务器套接字失败
- reactjs - React 库 + typescript + rollup 在 dist 文件夹中创建很多 d.ts 文件
- javascript - await 这个词实际上并没有 await 怎么办?
- java - 计算jar文件条目中的文件数
- python - 使用 t-SNE 和点连接可视化嵌入
- python - 击键加密
- r - 将 broom::glance 的结果附加在一起
- macos - 冲泡安装冻结
- angular-cli - 随着 Angular 11 图标在编译成 styles.css 时被损坏
- api - 自动记录每个邮递员的电话和对数据库的响应