"; System.Text.RegularExpressions.Regex regEx ...">

Exclude tag from regex not remove from text?

I have code like this

string pattern = "<(.|\n)+?>";
System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Reg(pattern);
string result = "";
result = regEx.Replace(htmlText, "");

This "htmlText" will have some HTML that also contains break tags. Now it replaces all html tags, but I want to leave the break tag and replace the rest. How should I do it? Anyone have an idea?

thank

+3
source share
2 answers

You can try the following:

<.? (?! w | / w) +>

+1
source

This should work:

string html = "<span>test<br><br /></span>";
Regex regex = new Regex("<[^(?!br)>]*>", RegexOptions.Compiled);
string result = regex.Replace(html, string.Empty);
0
source

Source: https://habr.com/ru/post/1788055/


All Articles