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 7660189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:25:56+00:00 2026-05-31T13:25:56+00:00

I have a large string and it might have the following: <div id=Specs class=plinks>

  • 0

I have a large string and it might have the following:

<div id="Specs" class="plinks">
<div id="Specs" class="plinks2">
<div id="Specs" class="sdfsf">
<div id="Specs" class="ANY-OTHER_NAME">

How can I replace values in the string from anything above to:

<div id="Specs" class="">

this is what I came up with, but it does not work:

        string source = "bunch of text";
        string regex = "<div id=\"Specs\" class=[\"']([^\"']*)[\"']>";
        string regexReplaceTo = "<div id=\"Specs\" class=\"\">";
        string output = Regex.Replace(source, regex, regexReplaceTo); 
  • 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-05-31T13:25:57+00:00Added an answer on May 31, 2026 at 1:25 pm

    If your input isn’t XML compliant, which most HTML isn’t, then you can use the HTML Agility Pack to parse the HTML and manipulate the contents. With the HTML Agility PAck, combined with Linq or Xpath, the order of your attributes no longer matters (which it does when you use Regex) and the overall stability of your solution increases a lot.

    Using the HTML Agility Pack (project page, nuget), this does the trick:

    HtmlDocument doc = new HtmlDocument();
    doc.LoadHtml("your html here"); 
    // or doc.Load(stream);
    
    var nodes = doc.DocumentNode.DescendantNodes("div").Where(div => div.Id == "Specs");
    
    foreach (var node in nodes)
    {
        var classAttribute = node.Attributes["class"];
        if (classAttribute != null)
        {
            classAttribute.Value = string.Empty;
        }
    }
    
    var fixedText = doc.DocumentNode.OuterHtml;
    //doc.Save(/* stream */);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large string, similar to this one: BREW pot HTCPCP/1.0 Accept-Additions: #milk;3#whiskey;splash
I have a large string I need to parse, and I need to find
I have a arbitrarily large string of text from the user that needs to
I have a large file(60mb) and I am reading the file into a string
I have this string containing a large chunk of html and am trying to
Let's say I have the following class structure: class Car; class FooCar : public
I have the following program to remove even numbers from a string vector, when
I have a large (3GB), gzipped file containing two fields: NAME and STRING. I
I have a very large JSON string that I need to parse with in-browser
I have a rather large spring application, and all I'm trying to share is

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.