$output = preg_replace("|(/D)(/s+)(/d+)(;)|", "//1,//3;", $output);
hello world 1007;
| at the start and end probably are incorrect - and should both be forward-slashes.
All other forward slashes should be backward slashes (and need escaping).
And since PHP 4.04
$n is the preferred way of referring to a capture group.
$output = preg_replace("/(\\D)\\s+(\\d+;)/", "$1,$2", $output);
If you use single quotes you don't need to escape your backslashes:
$output = preg_replace('/(\D)\s+(\d+;)/', '$1,$2', $output);