【发布时间】:2021-08-06 03:42:26
【问题描述】:
我一直在使用文本编辑器来完成我的正则表达式工作。它工作得很好,但现在我的示例文件大小为 10GB,所以它会阻塞文本编辑器。
您推荐使用什么,您是否有一些示例或网站可供参考?
我在看这是我发现人们使用它做很多事情的结果
- find - 是文件搜索
- grep - 是基于行的搜索
- awk - 是一种查找和替换搜索
- sed - 是一种编程语言搜索
我正在寻找的是:
你可以使用正则表达式:(.*), [a-z] then
文本文件:
some-text-file : threw this cat and then sat on the mat
some-other-text-file : the quick brown flew free then the fox fell
yet-another-text-file : i hope this explains this and that thoroughly
渴望
- 找到以 some 开头的那一行,然后找到“then”,然后从 then 到句子结尾的所有内容
- 输出主题:如果找到一些,则输入“Some:
- 如果找到“then”,则在同一行输出显示从该点到句子结尾的所有文本。
正则表达式(哪些可以只输出值而不是使用这种语法修改它?
我也想匹配多行并仅返回匹配文本。
找到: (^some)(.*)(then)(.*) 返回:主题:一些然后:\4结果:(搜索结果不是文件修改)
Subject: some Result: then sat on the mat
Subject: some Result: then the fox fell
yet-another-text-file : i hope this explains this and that thoroughly
【问题讨论】:
-
第三行怎么匹配?
-
那么你尝试了什么,你的问题是什么?
-
在您的示例输入/输出中包含类似
they ran then they walked then they sat的行,以便我们可以查看您是否希望输出从该行的第一个或最后一个then开始。并修正你的要求,说你想要Subject: some then:或Subject: some Result: then,但不是两者兼而有之。