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)']']~', '$1._______', $subject);