4

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.

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

2 Comments

i tried, this regex remove the string between : <span ..>-string-</span> i want to remov the tag but keep the string between the tag.
thank you!, this regex removing "<span> and </span>" and save the string between, but the regex not removing the "class=classname"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.