我有以下 html 代码,它的嵌套级别最高为 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>
我需要将 div 标签替换为 bbcode 并且我的正则表达式仅适用于未嵌套的剧透:
Regex.Replace(outstring,
@"<div class=""sp-body"" title=""(.*?)"">(.*?)</div>",
"[spoiler=$1]$2[/spoiler]",
RegexOptions.Singleline);