Question: I have a page that includes a list of lists and I'd like to navigate it with WatiN:

```
<div id="NestedLists">
    <ul>
        <li>
            <ul>
                <li>Sweet</li>
                <li>Sour</li>
                <li>Salty</li>
            </ul>
        </li>
        <li>
            <ul>
                <li>Red</li>
                <li>Yellow</li>
            </ul>
        </li>
    </ul>
</div>

```

I don't know how to loop through just the *direct* decendents of an Element. I thought this would work (note use of Lists and ListItems):

```
var treeControl = browser.Div(Find.ById("NestedLists"));
var listOfLists = treeControl.Lists.First();

Console.WriteLine("Outer List:");
foreach (var list in listOfLists.ListItems)
{
    Console.WriteLine("\tInner List:");
    foreach(var listItem in list.ListItems)
    {
        Console.WriteLine("\t\tList Item: " + listItem.Text);
    }
}

```

But that gives:

```
Outer List:
    Inner List:
        List Item: Sweet 
        List Item: Sour 
        List Item: Salty 
    Inner List:
    Inner List:
    Inner List:
    Inner List:
        List Item: Red 
        List Item: Yellow 
    Inner List:
    Inner List:

```

Answer: 
This should work

```
/(?<=%%EndResource).*?(?=showpage)/s

```

See it [here on Regexr](http://regexr.com?308bo)

`(?<=%%EndResource)` is a look behind assertion, it ensures that "%%EndResource" is before the part you want to get.

`(?=showpage)` is a look ahead assertion, it ensures that "%%EndResource" is following the part you want to get.

`.` is matching any character (including linebreaks becasue of the `s` modifier at the end)

`*?` matches any amount of characters and the empty string(!), but as less as possible (because of the `?`)
No regex is required here.

```
$start = strpos($the_string, "%%EndResource") + count("%%EndResource");
$end = strpos($the_string, "showpage")

$result = substr($the_string, $start, $end - $start);

```

Eventually add `trim()` if you want to loose the spaces.