首页 > 解决方案 > Notepad++ RegEx: Delete duplicate lines that are only duplicate from the beginning of the line up to a certain character(s)

问题描述

Long story short, I am trying to help the Final Fantasy XIV bard performance community by creating a simple voting system which disallows multiple votes from one person. Strawpoll is easy to cheat. ^^ So I've figured out how to do this, but I need help with a RegEx function in Notepad++.

We need to check for when a voter votes multiple times, and delete all those extra votes (and not delete the first vote). So in text terms, everything from the beginning of a line up to >> is what we are checking for duplicates of, and the part after >> in the lines is ignored in the search.

So then this:

VoterName1 >> Thancred
VoterName1 >> Minfilia
VoterName1 >> Thancred
VoterName2 >> Wedge
VoterName3 >> Thancred
VoterName3 >> Wedge
VoterName4 >> Biggs

Will look like this:

VoterName1 >> Thancred
VoterName2 >> Wedge
VoterName3 >> Thancred
VoterName4 >> Biggs

I've tried to find solutions myself by combining things I've seen online and fiddling around and trying to learn RegEx, but programming-thinking (or whatever you would call it) is just not my forte. Anyway, thanks so much for the help!

标签: regexduplicatesnotepad++

解决方案


用记事本++测试

搜索:

  • 如果用户名可以有空格:^((.+) >>.+)(\r?\n\2 .+)+
  • 如果用户名不能有空格:^((\S++).+)(\r?\n\2 .+)+

用。。。来代替:\1

它匹配第一个选民(第 2 组),然后在以该名称开头的行上引用它。您匹配所有这些行并通过第一个捕获组(整个第一行)替换它们

另外,在记事本++\n匹配\r\n所以你通常想\r在搜索时添加一个额外的\n


推荐阅读