Interesting challenge, I coded something that works for this sample, note that you need PHP 5.3+ for this code to work:
$regex = '^page/(?P<id>d+)-(?P<slug>[.]+).html$';
$args = array(
'id' => 5,
'slug' => 'my-first-article'
);
$result = preg_replace_callback('#(?P<(w+)>[^)]+)#', function($m)use($args){
if(array_key_exists($m[1], $args)){
return $args[$m[1]];
}
}, $regex);
$result = preg_replace(array('#^^|$$#', '#\\.#'), array('', '.'), $result); // To remove ^ and $ and replace . with .
echo $result;
Output: page/5-my-first-article.html
Online demo.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…