jCmk
jCmk

Reputation: 43

Vb.net Regex - remove html tags from string

My String Is :

<span class="name">name1</span><br> <span class="name">name2</span>


i want to remove : "<span ...>" and "</span>" from my string,

i can use the simple replace function, but regex is better because the operators.

i tried:

Regex.Replace(elm.InnerHtml, "<(.|\n)+?>", String.Empty)

but:

<(.|\n)+?>

remove all html tags , and i need to remove span only.

Upvotes: 4

Views: 8056

Answers (1)

burning_LEGION
burning_LEGION

Reputation: 13450

replace this regex <span.+?</span> with empty string

Regex.Replace(elm.InnerHtml, @"<span.+?</span>", String.Empty)

if you want save text between tags use this one </?span.*?>

Regex.Replace(elm.InnerHtml, @"</?span.*?>", String.Empty)

Upvotes: 3

Related Questions