Решение без регулярных выражений:
function transform($str) {
$prepared = str_replace(";", ",", $str);
$elements = explode(",", $prepared);
$transformedElements = array_map(function($element) {
return strpos($element, ":") === false ? $element : explode(":", $element)[1];
}, $elements);
return implode(",", $transformedElements);
}
$str = "value-1:test;2:test_2,test3";
$transformed = transform($str);
var_dump($transformed);
Оно же, но короче и менее читабельно:
$str = "value-1:test;2:test_2,test3";
$transformed = implode(",", array_map(function($element) {
return strpos($element, ":") === false ? $element : explode(":", $element)[1];
}, explode(",", str_replace(";", ",", $str))));
var_dump($transformed);