您的位置:首页 > 编程语言 > Python开发

Python 正则表达式去除重复行

2014-08-21 11:23 281 查看
1. Sort lines and remove adjacent duplicates
Match:
(?m)^([\s\S]*)(?:(?:\r?\n|\r)\1)+$
Replace:
\1

2. Keep the last occurrence of each duplicate line in an unsorted file
Match:
(?m)^([^\r\n]*)(?:\r?\n|\r)(?=[\s\S]*^\1$)
Replace:
None

3. Keep the first occurrence of each duplicate line in an unsorted file
Match:
(?m)^([^\r\n]*)$([\s\S]*?)(?:(?:\r?\n|\r)\1$)+
Repace:
\1\2
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: