preg_replace 个数字并在结果中使用

preg_replace digits and use in results

我将如何使用 preg_replace 来替换:

Some text is [[1]] and some is [[2]] bla bla...

进入这个:

Some text is 1.____________ and some is 2.____________ bla bla...

我有这个正则表达式可以找到正确的出现,但我不知道如何将替换数字添加到结果中?

preg_replace('(\[\[\d\]\])', '_______', $subject);

这让我得到了这个结果:

Some text is ____________ and some is ____________ bla bla...

您需要使用捕获组和对它的引用:

preg_replace('~\[\[(\d)\]\]~', '._______', $subject);