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