按模式删除相似单词的正则表达式 [英] Regex to remove similar words by pattern

查看:7
本文介绍了按模式删除相似单词的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Notepad++中有一个类似这样的列表

V - Visitors  2009 - S01e11-12.torrent
V - Visitors (2009) S02e04.torrent
V - Visitors (2009) S01e01-12.torrent
V S02e02.torrent
V S02e05.torrent
Valentina S01e01-13.torrent
Valeria Medico Legale S01-02e01-16.torrent
Veep - Season 1 BDMux.torrent
Veep - Season 2 BDMux.torrent
Veep - Season 3.torrent
Veep - Season 4.torrent
Vegas S01e01-21.torrent
Velvet S01e13.torrent
Velvet S01e15.torrent
Vikings.S03E03.torrent
Vikings.S03E04.torrent
Vikings.S03E05.torrent
Velvet_S03e02.torrent
Velvet_S03e03.torrent
Velvet_S03e04.torrent

我希望正则表达式删除重复的第一到第二个单词行(veep-veep)以获得如下所示的最终列表

V - Visitors  2009 - S01e11-12.torrent
V S02e02.torrent
Valentina S01e01-13.torrent
Valeria Medico Legale S01-02e01-16.torrent
Veep - Season 1 BDMux.torrent
Vegas S01e01-21.torrent
Velvet S01e13.torrent

所以如果我有

Veep - Season 1 BDMux.torrent
Veep - Season 2 BDMux.torrent

我只想要第一行

Veep - Season 1 BDMux.torrent

推荐答案

执行正则表达式查找/替换,如下所示:

  • 打开替换对话框
  • 查找内容:^([^ _.-]+[ _.-]+([^ _.-]++)?)(.*?R)(1.*?R)+
  • 替换为:13
  • 检查正则表达式
  • 单击"替换"或"全部替换"

说明

  • 前提条件是文件已排序
  • 第一部分^([^ _.-]+[ _.-]+([^ _.-]++)?)处理获取一行的第一个单词,后跟分隔符"","_",""。"或"-"。
    • 第一个单词是所有内容,而不是分隔符
    • 第二个单词(([^ _.-]++)?)是可选的,用于容纳天鹅绒 示例
    • 由于使用了括号,第一个单词、分隔符和可选的第二个单词被捕获到1中,然后包括换行符的内容被捕获到3中以供以后重用
  • (.*?R)捕获到换行符之前的所有内容(R
  • 最后一个参数(1.*?R)+匹配以1中捕获的内容开头的所有后续行
  • 匹配跨越所有行,它们将替换为13,并且仅重建第一行,从而删除以下行

这篇关于按模式删除相似单词的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆