[Solved] regular expression to replace div [closed]


This solution uses 2 Replace calls which might be OK if the code is not executed too frequently:

string input =
@"<div class=""tr-summaryinfo"">'
<p class=""tr-summaryitem"">test </>
</div>";

string result = Regex.Replace(input, 
     "<div class=\"tr-summaryinfo\">(.*?)</div>", 
     "<ul class=\"tr-summaryinfo\">$1</ul>",
    RegexOptions.Singleline);

result = Regex.Replace(result, 
     "<p class=\"tr-summaryitem\">(.*?)</p>", 
     "<li class=\"tr-summaryitem\">$1</li>",
    RegexOptions.Singleline);

Note that you need ? in the patterns to avoid the greedy behavior

Fiddle

11

solved regular expression to replace div [closed]