views:

12

answers:

1

My source string is this:

{categories group_id="3"}
{category_name}
{/categories}

{categories group_id="4"}
{category_name}
{/categories}

My regex is this:

preg_match('/{categories group_id="3"}(.*){\/categories}/s', $tagdata, $matches);

Which results in:

Array
(
    [0] => Array
        (
            [0] => {categories group_id="3"}
    {category_name}
    {/categories}
    {categories group_id="4"}
    {category_name}
    {/categories}
        )

    [1] => Array
        (
            [0] => 
    {category_name}
    {/categories}
    {categories group_id="4"}
    {category_name}

        )
)

You can see that the greediness is too greedy, and it goes all the way to the end of the second instance. What I'm expecting is this:

Array
(
    [0] => Array
        (
            [0] => {categories group_id="3"}
    {category_name}
    {/categories}
        )

    [1] => Array
        (
            [0] => 
    {category_name}

        )
)
+2  A: 
.*  greedy
.*? non-greedy
Wow. I feel dumb. Thanks.
Rob