Does it have to be preg_replace? Using preg_match you can extract the components of the string and recombine them to form your link:
<?php
$string = 'b $goog 780';
$pattern = '/(b \$([^\s]+) (\d+))/';
$matches = array();
preg_match($pattern, $string, $matches);
echo 'Buy <a href="/stocks/' . $matches[2] . '">$' . $matches[2] . '</a> at ' . $matches[3] ; // Buy <a href="/stocks/goog">$goog</a> at 780
What the pattern is looking for, is the letter 'b', followed by a dollar symbol (\$ - we escape the dollar as this is a special character in regex), then any and every character until it gets to a space ([^\s]+), then a space, and finally any number of numbers (\d+).