删除单词之间的重复字符 [英] remove repeated character between words
问题描述
我正在尝试来自 Regex 101
在任务 6 中,问题是
In Task 6, the question is
哦不!昨晚我的朋友似乎把啤酒洒在我的键盘上,现在我的按键非常粘.有时当我按下一个键时,我会得到两个重复项.你能 pppllleaaaseee 帮我解决这个问题吗?应删除粗体内容.
Oh no! It seems my friends spilled beer all over my keyboard last night and my keys are super sticky now. Some of the time when I press a key, I get two duplicates. Can you pppllleaaaseee help me fix this? Content in bold should be removed.
我已经尝试过这个正则表达式
([a-z])(\1{2})
但无法得到解决方案.
推荐答案
那个网站上的谜语的解决方案是:
The solution for the riddle on that website is:
/(.)\1{2}/g
由于键盘上的任何键都可能卡住,所以我们需要使用.
.
Since any key on the keyboard can get stuck, so we need to use .
.
\1
表示匹配 1st 捕获组 (.)
匹配的任何内容.
\1
in the regex means match whatever the 1st capturing group (.)
matches.
替换为 $1
或 \1
.
你的正则表达式的其余部分是正确的,只是有不必要的捕获组.
The rest of your regex is correct, just that there are unnecessary capturing groups.
这篇关于删除单词之间的重复字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!