Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定一个具有重复字符的字符串,删除相邻重复项的正确正则表达式是什么?我无法弄清楚如何使用反向引用来编写最终输出。例如。输入:“1111112222223333344444111”;输出:“12341”
你可以使用这个:
pattern: (.)\g{1}+ replacement: $1
或这个:
pattern: (.)\K\g{1}+
没有什么可以更换的
以 php 为例:
preg_replace('~(.)\K\g{1}+~', '', '1111112222223333344444111');