- preg_replace_callback: documentation ( source)
- preg_match: documentation ( source)
<?php
$str = 'fdfqsdfqsdf%A%2%B%4%C%D%7sddsdfsdf';
$res = preg_replace_callback(',%.?,', function (array $matches) {
if (preg_match(',%\d+,', $matches[0])) {
return 'FOO';
}
}, $str);
echo $res;
$res = preg_replace_callback(',%\d+?,', function (array $matches) {
return 'FOO';
}, $str);
echo $res;