Note that there are some explanatory texts on larger screens.

plurals
  1. PORecursive regex for div tags(not trying to parse html with regex)
    primarykey
    data
    text
    <p>I have a bunch of wiki markup, sometimes people just throw random html down in the middle of wiki markup and somehow wikipedia just rolls with it, as it does for all kinds of other badly formed wiki markup. I want to match everything inside the divs.</p> <p>I need to recursively find all the <code>&lt;div&gt;blah&lt;/div&gt;</code> tags including div tags with other div tags inside them. I am trying to match the div tags and everything inside of them. I have this which I believe almost works:</p> <pre><code>new Regex(@"\&lt;div.*?\&gt; (?&lt;DEPTH&gt;) # opening (?&gt; # now match... [^(\&lt;div.*?\&gt;)(\&lt;\/div\&gt;)]+ # any characters except divs | # or \&lt;div.*?\&gt; (?&lt;DEPTH&gt;) # a opening div, increasing the depth counter | # or \&lt;\/div\&gt; (?&lt;-DEPTH&gt;) # a closing div, decreasing the depth counter )* # any number of times (?(DEPTH)(?!)) # until the depth counter is zero again \&lt;\/div\&gt; # then match the closing fix", RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline); </code></pre> <p>Maybe I should be using another methodology to parse this but at this point this is the final regex statement that I need.</p> <p>Here is an example:</p> <pre><code>&lt;div class="infobox sisterproject" style="font-size: 90%; padding: .5em 1em 1em 1em;"&gt; &lt;div style="text-align:center;"&gt; Find more about '''{{{display|{{{1|{{PAGENAME}}}}}}}}''' on Wikipedia's [[Wikipedia:Wikimedia sister projects|sister projects]]: &lt;/div&gt;&lt;!-- --&gt;{{#ifeq:{{{wikt}}}|no||&lt;!-- --&gt;[[File:Wiktionary-logo-en.svg|25px|link=wikt:Special:Search/{{{wikt|{{{1|{{PAGENAME}}}}}}}}|Search Wiktionary]] [[wikt:Special:Search/{{{wikt|{{{1|{{PAGENAME}}}}}}}}|Definitions]] from Wiktionary&lt;br /&gt;}}&lt;!-- --&gt;{{#ifeq:{{{b}}}|no||&lt;!-- --&gt;[[File:Wikibooks-logo.svg|25px|link=b:Special:Search/{{{b|{{{1|{{PAGENAME}}}}}}}}|Search Wikibooks]] [[b:Special:Search/{{{b|{{{1|{{PAGENAME}}}}}}}}|Textbooks]] from Wikibooks&lt;br /&gt;}}&lt;!-- --&gt;{{#ifeq:{{{q}}}|no||&lt;!-- --&gt;[[File:Wikiquote-logo.svg|25px|link=q:Special:Search/{{{q|{{{1|{{PAGENAME}}}}}}}}|Search Wikiquote]] [[q:Special:Search/{{{q|{{{1|{{PAGENAME}}}}}}}}|Quotations]] from Wikiquote&lt;br /&gt;}}&lt;!-- --&gt;{{#ifeq:{{{s}}}|no||{{#ifeq:{{{author|no}}}|yes|&lt;!-- --&gt;[[File:Wikisource-logo.svg|25px|link=s:Special:Search/Author:{{{s|{{{1|{{PAGENAME}}}}}}}}|Search Wikisource]] [[s:Special:Search/Author:{{{s|{{{1|{{PAGENAME}}}}}}}}|Source texts]] from Wikisource&lt;br /&gt;|&lt;!-- --&gt;[[File:Wikisource-logo.svg|25px|link=s:Special:Search/{{{s|{{{1|{{PAGENAME}}}}}}}}|Search Wikisource]] [[s:Special:Search/{{{s|{{{1|{{PAGENAME}}}}}}}}|Source texts]] from Wikisource&lt;br /&gt;}}}}&lt;!-- --&gt;{{#ifeq:{{{commons}}}|no||&lt;!-- --&gt;[[File:Commons-logo.svg|25px|link=commons:Special:Search/{{{commons|{{{1|{{PAGENAME}}}}}}}}|Search Commons]] [[commons:Special:Search/{{{commons|{{{1|{{PAGENAME}}}}}}}}|Images and media]] from Commons&lt;br /&gt;}}&lt;!-- --&gt;{{#ifeq:{{{n}}}|no||&lt;!-- --&gt;[[File:Wikinews-logo.svg|25px|link=n:Special:Search/{{{n|{{{1|{{PAGENAME}}}}}}}}|Search Wikinews]] [[n:Special:Search/{{{n|{{{1|{{PAGENAME}}}}}}}}|News stories]] from Wikinews&lt;br /&gt;}}&lt;!-- --&gt;{{#ifeq:{{{v}}}|no||&lt;!-- --&gt;[[File:Wikiversity-logo-Snorky.svg|25px|link=v:Special:Search/{{{v|{{{1|{{PAGENAME}}}}}}}}|Search Wikiversity]] [[v:Special:Search/{{{v|{{{1|{{PAGENAME}}}}}}}}|Learning resources]] from Wikiversity&lt;br /&gt;}}&lt;!-- --&gt;{{#ifeq:{{{species&lt;includeonly&gt;|no&lt;/includeonly&gt;}}}|no||&lt;!-- --&gt;[[File:Wikispecies-logo.svg|25px|link=species:Special:Search/{{{species&lt;noinclude&gt;|{{{1|{{PAGENAME}}}}}&lt;/noinclude&gt;}}}|Search Wikispecies]] [[species:Special:Search/{{{species&lt;noinclude&gt;|{{{1|{{PAGENAME}}}}}&lt;/noinclude&gt;}}}|{{{species&lt;noinclude&gt;|{{{1|{{PAGENAME}}}}}&lt;/noinclude&gt;}}}]] from Wikispecies}} &lt;/div&gt;&lt;noinclude&gt; </code></pre> <p>Thanks</p>
    singulars
    1. This table or related slice is empty.
    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.
    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