RegEx删除所有双(或更多)字母 - > preg_replace

时间:2021-11-03 16:54:25

Helo,

直升机,

I've this RegEx to delete double letter on a string :

我有这个RegEx删除字符串上的双字母:

<?
$string = "Heeeeelloo";
echo preg_replace( '`(.*)\1`', '$1',$string)."\n";

The current result is : Heeelo

目前的结果是:Heeelo

But i would like this result : Helo

但是我想要这个结果:Helo

What's wrong ? Thanks

怎么了 ?谢谢

1 个解决方案

#1


3  

Just do:

做就是了:

preg_replace( '`(.)\1+`', '$1',$string);

#1


3  

Just do:

做就是了:

preg_replace( '`(.)\1+`', '$1',$string);