我有一个巨大的文本文件要排序,我注意到,我不需要的行通常带有连字符-符号和多于3行的一行。所以我想用regex删除这些行。
我试过这样做:^.*(?:\-.*?){3}.*(?:\R|\Z),但是它只在一行中工作,而我只需要删除从3到更多的-开始的连续行。
我的文本示例:
Good Line 1
Error-1
Error-2:3045
Error-3-32
Good Line 2
Error-4_sub
Error-5.0
Error-6...0
Error-7
Error-8-9
Error-9
Good Line 3期望输出
Good Line 1
Good Line 2
Good Line 3发布于 2021-05-21 00:50:45
我会用..。
找到什么:^(?:.*Error-).*\s?
替换为:nothing
这将找到任何有Error-的行并删除它..。
解释
^ # beginning of line
(?: # Beginning non capture group
.* # 0 or more any character but newline,
Error- # literally Error plus hyphen
) # closing of non captured group
.* # 0 or more any character but newline
\s # matches any whitespace character (equivalent to [\r\n\t\f\v ])
? # matches the previous token between zero and one times, as many times as possible, giving back as needed (greedy) https://stackoverflow.com/questions/61561884
复制相似问题