I have the following html code, which have nesting up to level 3:
<div class="sp-wrap">
<div class="sp-body" title="FAQ">
Some text
<div class="sp-wrap">
<div class="sp-body" title="title1"> // Level 2
Text1...
</div>
</div>
<div class="sp-wrap">
<div class="sp-body" title="title2"> // Level 2
Text2...
</div>
</div>
<div class="sp-wrap">
<div class="sp-body" title="title3"> // Level 2
Text3...
<div class="sp-wrap">
<div class="sp-body" title="title4"> // Level 3
Text4...
</div>
</div>
</div>
</div>
</div>
I need to replace div tags into bbcode and my regular expression work only for not nested spoilers:
Regex.Replace(outstring,
@"<div class=""sp-body"" title=""(.*?)"">(.*?)</div>",
"[spoiler=$1]$2[/spoiler]",
RegexOptions.Singleline);
Did not test, but the idea should work:
EDIT:
Should produce something like
As you can see it’s not perfectly indented (could be fixed, I guess) and detects one missing
</div>in the example.