preg_replace regex take too much from string, want to replace text inner [duplicate]

have a problem with preg_replace.
I have BBCodes and want them replace.
lets say i want to replace the attach bbcode with attachment id: 35318

String:

[ATTACH]35316[/ATTACH][ATTACH]35318[/ATTACH]
[ATTACH]35317[/ATTACH]

preg_replace:

preg_replace('/[ATTACH(.*)]35318[/ATTACH]/', '[ATTACH type="full" alt="test" width="250px"]35318[/ATTACH]', $input_lines);

it deletes

[ATTACH]35316[/ATTACH]

result:

[ATTACH type="full" alt="test" width="250px"]35318[/ATTACH]
[ATTACH]35317[/ATTACH]

need result:

 [ATTACH]35316[/ATTACH][ATTACH type="full" alt="test" width="250px"]35318[/ATTACH][ATTACH]35317[/ATTACH]

is there a solution with preg_replace to take inner replace from the 35318

my solution, but it is a workaround:
put whitespaces between closing attach and opening attach and then run preg_replace and after that remove whitespaces between closing attach and opening attach