Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
I doubt. that one regular expression can do this.
I guess you need something like this:
$str = "abababcdcdcdabab";
$parts = preg_split('/([a-z]{2})/u', $str, 0, PREG_SPLIT_DELIM_CAPTURE);
$parts = array_values(array_filter($parts));
$skip = 0;
$result = '';
foreach($parts as $id => $part) {
$next = isset($parts[$id+1]) ? $parts[$id+1] : false;
if ($part == $next) {
++$skip;
}
if ($skip == 2) {
$skip = 0;
continue;
}
$result .= $part;
}
echo $result;
$str = "abababababcdcdcdcdcdabab";
$parts = preg_split('/([a-z]{2})/u', $str, 0, PREG_SPLIT_DELIM_CAPTURE);
$parts = array_values(array_filter($parts));
$skip = 0;
$last = '';
$result = '';
foreach($parts as $id => $part) {
$next = isset($parts[$id+1]) ? $parts[$id+1] : false;
if ($part == $next) {
++$skip;
} else {
$skip = 0;
}
if ($skip >= 2) {
continue;
}
$result .= $part;
}
echo $result;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question