$re = '/\<(ol)(?: .*?)?\>(?:[^\<]|\<(.*?)\>.*\<\/\2\>)*\<\/\1\>/s';
$str = '<ol>kjkjkj
</ol>
<ol s>
<li>Table of Contents.....................CT.TS</li>
<li>Gamecube Controls.....................CN.GC</li>
<li>Nintendo 64 Controls..................CN.64</li>
<li>Walkthrough...........................01.00
<ol>
<li>Kokiri Forest...............01.01</li>
</ol>
</li>
<li>Sidequests & Minigames................02.00
<ol>
<li>Shooting Gallery............02.01</li>
</ol>
</li>
<li>Boss Guide............................03.00
<ol>
<li>Gohma.......................03.01</li>
<li>Final Boss [Second Form]....03.15</li>
</ol>
</li>
<li>Item Checklist........................04.00
<ol>
<li>Final Dungeon...............04.47</li>
</ol>
</li>
<li>Shop Inventory........................05.00
<ol>
<li>Kokiri Shop [Young].........05.01</li>
<li>Goron Shop [Adult]..........05.09</li>
</ol>
</li>
<li>Ocarina Notes.........................06.00
<ol><ol>sdsds</ol>
<li>Requ<ol></ol>iem of Spirit...........06.12</li>
</ol>
</li>
<li>Heart Containers......................07.00</li>
<li>Item List.............................15.00</li>
<li>Legal & Copyright.....................LE.AL</li>
<li>Credits & Thanks......................CR.DS</li>
</ol>
<ol><ol><ol><ol><ol></ol></ol></ol></ol></ol>
sdsd
k<ol>jlkjlkj
kjbkjh</ol> ';
preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0);
// Print the entire match result
var_dump($matches);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php