Note that there are some explanatory texts on larger screens.

plurals
  1. PORegEx: Including an attribute check in the same element
    text
    copied!<p><strong>The end aim</strong>... to retrieve a group of DIVs with specific attributes/values and update the element type and manipulate the attribute and value...</p> <p>I'd like to use RegEx to test the following <strong>scenario</strong> (I believe is correct based on the above aim)</p> <ul> <li>for each opening DIV</li> <li>that contains an <code>attribute-to-check</code> attribute <ul> <li>The attribute may or may <em>not</em> be the first attribute</li> </ul></li> <li>that has a value containing <code>value-contains</code> <ul> <li>The value may or may <em>not</em> be the first value in the attribute (allowing for future extensions)</li> </ul></li> <li>find <strong>its</strong> closing DIV <ul> <li>This DIV itself may contain other DIVs - <strong>including</strong> other DIVs that will also be matched</li> </ul></li> </ul> <p>So what have I <strong>tried</strong>? ...Using the test script:</p> <pre><code>&lt;p&gt;test1&lt;/p&gt; &lt;DIV attribute-to-check='notvalid'&gt; test2 &lt;/DIV&gt; &lt;p&gt;test3&lt;/p&gt; &lt;DIV attribute-to-check='value-contains:2012-12-12' class='test4'&gt; test5 &lt;/DIV&gt; &lt;p&gt;test6&lt;/p&gt; &lt;DIV attribute-to-check='value-contains:2012-01-01' class='asd'&gt; test6 &lt;/DIV&gt; &lt;p&gt;test7&lt;/p&gt; </code></pre> <p>I've got as far as the following RegEx...</p> <pre><code>&lt;?DIV.*?attribute-to-check='value-contains:.*?&gt;(.*?)&lt;/DIV&gt; </code></pre> <p>BUT this brings back </p> <pre><code>string 1: "&lt;DIV attribute-to-check='notvalid'&gt;test2&lt;/DIV&gt;test3&lt;DIV attribute-to-check='value-contains:2012-12-12' class='test4'&gt;test5&lt;/DIV&gt;" string 2: "&lt;DIV attribute-to-check='value-contains:2012-01-01' class='asd'&gt;test6&lt;/DIV&gt;" </code></pre> <p>I suspect it's bringing back <code>test2</code> in string1 as this has an opening div with the attribute-to-check <em>but</em> the value is notvalid? so I'm wondering if I'm getting the first DIV then any number of characters until it locates <em>any</em> other <code>attribute-to-check='value-contains:</code> and then the closing DIV after that? </p> <p>I am struggling to navigate from this point and would appreciate any helpers from the community :)</p> <p>Thanks Dylan</p>
 

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