regex - 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!
解决方案
用记事本++测试
搜索:
- 如果用户名可以有空格:
^((.+) >>.+)(\r?\n\2 .+)+
- 如果用户名不能有空格:
^((\S++).+)(\r?\n\2 .+)+
用。。。来代替:\1
它匹配第一个选民(第 2 组),然后在以该名称开头的行上引用它。您匹配所有这些行并通过第一个捕获组(整个第一行)替换它们
另外,在记事本++\n
中不匹配\r\n
所以你通常想\r
在搜索时添加一个额外的\n
推荐阅读
- javascript - 无法返回 Fetch API 接收到的数据
- authentication - Keycloak 是否像 Auth0 一样提供嵌入式登录?
- postgresql - 创建错误的点值
- python - 如何制作 Python 脚本以获得回报?
- java - Java:使静态类(不是实例)符合接口
- node.js - 无法将正则表达式与文本匹配
- reactjs - 是否可以使用 Algolia 和 Instant-Search 对两个不同的 UI 进行 A/B 测试?
- php - PHP:访问在一个函数中声明的变量,在另一个函数中
- javascript - 在 JQuery 中向 .text() 方法添加换行符?
- reactjs - 如何覆盖 react-hooks 组件内的函数测试 - Enzyme/Jest