3
我将如何使用的preg_replace替换:的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...
奇怪的是,在这里工作的http://www.phpliveregex .com/p/bLH,但不在我的电脑上。我只得到________? –
是的,现在没关系! –
仅供参考,这不是一个back_reference,而是一个捕获组,最好在替换零件中使用'$ 1'而不是'\ 1'。 – Toto