Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:32:46+00:00 2026-06-07T03:32:46+00:00

I want to strip html string for Span tags. I have a html string

  • 0

I want to strip html string for Span tags.

I have a html string :

<a href=\"http://www.dr.dk/roskilde\"><span>Roskilde</span><span>Festival</span></a>

I need to strip it down to : Roskilde Festival.

Atm, I have a regex string which should be able to find all span tags, but its failing

 System.Collections.Specialized.StringCollection sc = new System.Collections.Specialized.StringCollection();

    sc.Add(@"/<\s*\/?\s*span\s*.*?>/g");


    foreach (string s in sc)
    {
        k = System.Text.RegularExpressions.Regex.Replace(pContent, s, "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
    }
    k = System.Text.RegularExpressions.Regex.Replace(pContent, @"&nbsp;", @"&#160;");                                                              

Any Ideas?

P.S. I don’t wnat to use Html Agility Pack

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:32:47+00:00Added an answer on June 7, 2026 at 3:32 am

    Regexp are not the best way to process HTML. Use a HTML parser that understands nesting, because Regexp do not understand HTML nesting.

    Consider looking at inverse charsets, i.e. <whatever[^>]*>

    And I guess you copied this from somewhere, but your regexp probably is not the proper C# syntax (extra / and /g). Reread a regexp in C# tutorial! Try this string:

    Example /<span>/g does this tag get removed?
    

    What you probably meant to use was:

    sc.Add(@"</?span( [^>]*|/)?>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to strip all html tags from a string except some I specify.
I want to strip script tags out of this HTML at Pastebin: http://pastebin.com/mdxygM0a I
i want to strip all the html tags from a string except ( <img>
I want to strip tags from a html, but preserves it's line breaks. I
I want to strip image URLs from lots of differently formed HTML. I have
Possible Duplicate: PHP: Strip a specific tag from HTML string? Hi All, I want
I want to index Html text with the FrenchAnalyzer so I need to strip
I want to check some string before sending an email. I have 3 fields:
I want to use php's strip tags in a bash script. I figured I
I have a string that represents an html document. I'm trying to replace text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.