Regex C#- Everything Before, Between and After [T][/T]
<p>I've this regex</p>

<pre><code>([\s\S]*?)\[T\]([\s\S]*?)\[\/T\]([\s\s]*?)
</code></pre>

<p>Which is supposed to extract everything before, between and after <code>[T][\T]</code>, but I always get the third capturing group empty. </p>

<p>My text is:</p>

<pre><code>&lt;h1&gt;HelloWorld&lt;/h1&gt;
[T]
 &lt;h2&gt;I'm Inside&lt;/h2
[/T]
&lt;h1&gt;HelloWorld&lt;/h1&gt;
[T]
 &lt;h2&gt;I'm Inside&lt;/h2
[/T]
&lt;h3&gt;By World&lt;/h3&gt;
</code></pre>

<p>I've used <a href="http://www.regexr.com" rel="nofollow noreferrer">Regexr</a> and <a href="http://www.regex101.com" rel="nofollow noreferrer">Regex101</a> And came to the conclusion that the mistake was in the <code>?</code> on the last capturing group <code>([\s\S]*?)</code>, beacuse is doing the <code>*</code> lazy. However if I remove it it groups everything as a single match instead of two.</p>

<p><strong>EDIT:</strong></p>

<p>Basically I want to do something like </p>

<pre><code>var template = @"    &lt;h1&gt;HelloWorld&lt;/h1&gt;
    [T]
     &lt;h2&gt;I'm Inside&lt;/h2
    [/T]
    &lt;h1&gt;HelloWorld&lt;/h1&gt;
    [T]
     &lt;h2&gt;I'm Inside&lt;/h2
    [/T]
    &lt;h3&gt;By World&lt;/h3&gt;";

var regex = new Regex("([\s\S]*?)\[T\]([\s\S]*?)\[\/T\]([\s\s]*?)");
var finalString = regex.Replace(template,"$1 ; $2 ; $3");

// finalString = HelloWorld ; I'm Inside ; By World //
</code></pre>

<p>Any help appreciated.</p>