This is not possible with just a regexp.
You can solve it by first using preg_match_all() to find all the <code> </code> blocks and store them in an array.
Then you can make a copy of that array, and process all it's elements using htmlspecialchars().
Then you can use preg_replace() to replace the elements from the original array (the code blocks) with the elements from the new array (the code blocks after they have been run through htmlspecialchars).
Tricky, but it can be done.
A forum, a FAQ, what else do you need?