gpt4 book ai didi

regex - 删除单词之间的重复字符

转载 作者:行者123 更新时间:2023-12-03 23:32:21 25 4
gpt4 key购买 nike

我正在尝试 Regex 101 的测验

在任务 6 中,问题是

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.



我试过 this regex
([a-z])(\1{2})

但无法得到解决方案。

最佳答案

该网站上的谜语的解决方案是:

/(.)\1{2}/g

由于键盘上的任何键都可能卡住,因此我们需要使用 .

正则表达式中的 \1 表示匹配第一个捕获组 (.) 匹配的任何内容。

替换为 $1\1

您的正则表达式的其余部分是正确的,只是有不必要的捕获组。

关于regex - 删除单词之间的重复字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14083133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com