我有一个巨大的文本文件需要排序,我注意到我不需要的行通常带有连字符 -
符号并且连续超过 3 行。所以我想使用正则表达式来删除这些行。
我尝试了这个: ^.*(?:\-.*?){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
最佳答案
- Ctrl+H
- 查找内容:
(?:^.*?-.*(?:\R|\z)){4,}
- 替换为:
LEAVE EMPTY
- 检查 环绕
- 检查 正则表达式
- 取消选中
。匹配换行符
- 全部替换
说明:
(?: # Beginning non capture group
^ # beginning of line
.*? # 0 or more any character but newline, not greedy
- # hyphen
.* # 0 or more any character but newline
(?:\R|\z) # non capture group, any kind of linebreak OR end of file
){4,} # end group, must appear 4 or more times
# set the value to your needs
屏幕截图(之前):
屏幕截图(之后):
书签行:
关于正则表达式删除具有特定符号的连续行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61561884/