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

  • Home
  • SEARCH
  • 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 82653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:39:02+00:00 2026-05-10T21:39:02+00:00

Before anybody asks, I am not doing any kind of screenscraping. I’m trying to

  • 0

Before anybody asks, I am not doing any kind of screenscraping.

I’m trying to parse an html string to find a div with a certain id. I cannot for the life of me get this to work. The following expression worked in one instance, but not in another. I’m not sure if it has to do with extra elements in the html or not.

<div\s*?id=(\''|&quot;|&#34;)content(\''|&quot;|&#34;).*?>\s*?(?>(?! <div\s*?> | </div> ) | <div\s*?>(?<DEPTH>) | </div>(?<-DEPTH>) | .?)*(?(DEPTH)(?!))</div> 

It is finding the first div with the right id correctly, but it then closes at the first closing div, and not the related div.

<div id='firstdiv'>begining content<div id='content'>some other stuff     <div id='otherdiv'>other stuff here</div>     more stuff     </div> </div> 

This should bring back

<div id='content'>some other stuff    <div id='otherdiv'>other stuff here</div>    more stuff </div> 

, but for some reason, it is not. It is bring back:

   <div id='content'>some other stuff       <div id='otherdiv'>other stuff here</div> 

Does anybody have an easier expression to handle this?

To clarify, this is in .NET, and I’m using the DEPTH keyword. You can find more details here.

  • 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. 2026-05-10T21:39:03+00:00Added an answer on May 10, 2026 at 9:39 pm

    In .NET you can do this:

    (?<text> (<div\s*?id=(\'|&quot;|&\#34;)content(\'|&quot;|&\#34;).*?>)    (?>       .*?</div>     |       .*?<div (?>depth)     |       .*?</div> (?>-depth)   )*)   (?(depth)(?!)) .*?</div> 

    You must use the singleline option. Here is an example using the console:

    using System; using System.Text.RegularExpressions;  namespace Temp {     class Program     {         static void Main()         {             string s = @' <div id=''firstdiv''>begining content<div id=''content''>some other stuff   <div id=''otherdiv''>other stuff here</div>   more stuff   </div> </div>';             Regex r = new Regex(@'(?<text>(<div\s*?id=(\''|&quot;|&\#34;)'                 + @'content(\''|&quot;|&\#34;).*?>)(?>.*?</div>|.*?<div '                 + @'(?>depth)|.*?</div> (?>-depth))*)(?(depth)(?!)).*?</div>',                 RegexOptions.Singleline);             Console.WriteLine('HTML:\n');             Console.WriteLine(s);             Match m = r.Match(s);             if (m.Success)             {                 Console.WriteLine('\nCaptured text:\n');                 Console.WriteLine(m.Groups[4]);              }             Console.ReadLine();         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 62k
  • Answers 62k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer Attributes are fine because they are truly part of the… May 11, 2026 at 10:15 am
  • added an answer SELECT * FROM table WHERE date_time BETWEEN '2009-03-27 00:00:00' AND… May 11, 2026 at 10:15 am
  • added an answer No matter what people say GC will do for you,… May 11, 2026 at 10:15 am

Related Questions

Before anybody asks, I am not doing any kind of screenscraping. I'm trying to
Before you answer this I have never developed anything popular enough to attain high
Before I start, I know there is this post and it doesn't answer my
Before I do this I figured I would ask if it was the best
Before I jump headlong into C#... I've always felt that C, or maybe C++,
Before, I have found the Cost in the execution plan to be a good
Before moving on to use SVN, I used to manage my project by simply
Before anyone suggests scrapping the table tags altogether, I'm just modifying this part of
Before I upgraded to Firefox 3 I used to constantly use the View Source
Before you start firing at me, I'm NOT looking to do this, but someone

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.