让我说,我有这个
video_upper_div
我怎样才能做到这一点?我试过Hello ??? WHERE ARE YOU!!!! Comon ?!?!?!
desired outout
Hello ? WHERE ARE YOU!!!! Comon ?!
,但没有运气。我使用Finding the shortest repetitive pattern in a string作为起点,但它适用于完整的句子,我需要它逐字逐句地工作+我需要删除重复的计算(模式)? Live Code
答案 0 :(得分:0)
将\?+
替换为?
,!+
替换为!
,(\?!)+
替换为?!
,依此类推。
function dedup_punctuation($str) {
$targets = array('/\?+/', '/!+/', '/(\?!)+/');
$replacements = array('?' , '!' , '?!' );
return preg_replace($targets, $replacements, $str);
}
答案 1 :(得分:0)
使用以下代码:
$str = "Hello ??? WHERE ARE YOU!!!! Comon ?!?!?! ...";
$replacement = [
'?',
'?!',
'.',
];
foreach( $replacement as $key => $value ){
$pattern[$key] = sprintf("/(\%s)+/", $value);
}
echo $outout = preg_replace($pattern, $replacement, $str);
将任何标点符号插入替换数组以删除重复的标点符号。