language: PHP (php 5.4.4)
date: 624 days 2 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
<?php 
$subject = "Replace ? question mark in brackets [? with ? incremental ??]? digits";
echo preg_replace_callback('/\[[^\]]+\]/', 'replaceThem', $subject);
function replaceThem($matches){
    $i = 1;
    while ($pos = strpos($matches[0], '?'))
        $matches[0][$pos] = $i++;
    return $matches[0];
}