php preg_replace模式

I need a hand on my preg_replace pattern:

I want to replace the texts between brackets [] but also inside brackets and not only until the first one [.[.].....] and the same pattern but to replace only numbers inside those brackets.

any idea?

Try this regex:

$re = '#\[(?:.*?(?0))*.*?\]#'

This will match a [...] pair, which may itself contain one or more [...] pairs, with any characters between them. This is done by using recursion in the pattern (the (?0) calls the pattern again).

preg_match($re, '[.[.]....]', $m);
print_r($m);

// Output:
// Array
// (
//    [0] => [.[.]....]
// )