 <p>This will capture the two square brackets <code>\K\[\[(?&gt;[^]]++|](?!]))]]*</code> </p> <p><strong>Input Text</strong></p> <pre><code>like [[ yes|ja ]] with </code></pre> <p><strong>Matches</strong></p> <pre><code>[0] =&gt; [[ yes|ja ]] [1] =&gt; yes|ja </code></pre> <p>I"m not a python programmer, but I think you'll want to modify your script to be like this:</p> <pre><code>$that = $this; $view = preg_replace_callback('~\K\[\[(?&gt;[^]]++|](?!]))]]*~', function ($m) use ($that) { return $that-&gt;__($m[1]); }, $view); </code></pre>