Note that there are some explanatory texts on larger screens.

plurals
  1. PORegex - Find Content of div by id with nested divs
    primarykey
    data
    text
    <p>Before anybody asks, I am not doing any kind of screenscraping.</p> <p>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.</p> <pre><code>&lt;div\s*?id=(\""|&amp;quot;|&amp;#34;)content(\""|&amp;quot;|&amp;#34;).*?&gt;\s*?(?&gt;(?! &lt;div\s*?&gt; | &lt;/div&gt; ) | &lt;div\s*?&gt;(?&lt;DEPTH&gt;) | &lt;/div&gt;(?&lt;-DEPTH&gt;) | .?)*(?(DEPTH)(?!))&lt;/div&gt; </code></pre> <p>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.</p> <pre><code>&lt;div id="firstdiv"&gt;begining content&lt;div id="content"&gt;some other stuff &lt;div id="otherdiv"&gt;other stuff here&lt;/div&gt; more stuff &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This should bring back</p> <pre><code>&lt;div id="content"&gt;some other stuff &lt;div id="otherdiv"&gt;other stuff here&lt;/div&gt; more stuff &lt;/div&gt; </code></pre> <p>, but for some reason, it is not. It is bring back:</p> <pre><code> &lt;div id="content"&gt;some other stuff &lt;div id="otherdiv"&gt;other stuff here&lt;/div&gt; </code></pre> <p>Does anybody have an easier expression to handle this?</p> <p>To clarify, this is in .NET, and I'm using the DEPTH keyword. You can find more details <a href="http://www.m-8.dk/resources/RegEx-Balancing-Group.aspx" rel="noreferrer">here</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload