正则表达式删除重复字母 [英] Regex to remove duplicate letters
问题描述
我在 Notepad++ 中有一个文档,其中每一行可以有任意字符组合.例如:
I have a document in Notepad++ where each line can have any combination of characters. For example:
RRGG
U
XB
UUGG
UG
我想要的是删除任何重复字符的正则表达式.因此,鉴于上述情况,我将得到:
What I would like, is a regex to remove any duplicate characters. So, given the above, I would be left with:
RG
U
XB
UG
UG
我尝试根据我在网上看到的内容找到 ([a-z])
并替换为 \1
,但我一无所获.我什至试图找到 ([az])+
,但这只是让我得到了最后一个字母(不知道为什么我认为这会起作用,除了我在正则表达式方面很糟糕).我也不想摆脱任何空格或空行.这样做的最佳方法是什么?
I've tried finding ([a-z])
and replacing with \1
based on something I'd seen online, but I got nothing. I've even tried finding ([a-z])+
, but that just got me the last letter on the line(not sure why I thought that would work, other than I'm horrible at regex). I also don't want to get rid of any whitespace, or empty lines. What's the best way to do this?
推荐答案
查找:
([A-Z])\1+
替换为:
\1
这篇关于正则表达式删除重复字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!