I need to replace BBCode quotes from a phpBB3 forum using PHP. Quoted posts look like this:

```
[quote=&quot;John Doe&quot;:2sxn61wz][quote=&quot;Bob&quot;:2sxn61wz]Some text from Bob[/quote:2sxn61wz]Some text from John Doe[/quote:2sxn61wz]Some more text

```

I would like to parse this string and end up with an array like:

```
Array (

    [0] => Array (

        [0] => 'John Doe' 
        [1] => 'Some text from John Doe'
    )

    [1] => Array (

        [0] => 'Bob' 
        [1] => 'Some text from Bob'
    )
)

```

What would be the best approach to recursively find these quote blocks and their content? Thanks in advance for any help on that!

**As suggested in the comments:**

```
$str = '[quote=&quot;John Doe&quot;:2sxn61wz][quote=&quot;Bob&quot;:2sxn61wz]Some text from Bob[/quote:2sxn61wz]Some text from John Doe[/quote:2sxn61wz]Some more text';
$uid = '2sxn61wz';

print_r(quoteParser($str, $uid));

function quoteParser($str, $uid) {

    $pattern = "#\[quote(?:=&quot;(.*?)&quot;)?:$uid\]((?!\[quote(?:=&quot;.*?&quot;)?:$uid\]).)?#ise";

    echo "Unparsed string: " . $str . "<br /><br />";
    echo "Pattern: " . $pattern . "<br /><br />";

    preg_match_all($pattern, $str, $matches);

    return $matches;
}

```

**Output:**

```
Array ( [0] => Array ( [0] => [quote="John Doe":2sxn61wz] [1] => [quote="Bob":2sxn61wz]S ) [1] => Array ( [0] => John Doe [1] => Bob ) [2] => Array ( [0] => [1] => S ) ) 

```

That's quite what I need but I don't get the quoted text. Only the user names. Any help? Thanks so far.