i don't use the posix functions (ereg, eregi, etc) so I don't know if they support ungreedy matching or not. There is really no good reason to use them from what I know of them, as the perl-compatible regex functions are faster and have more features
here's how you would do that using preg_match() :
the ? after the .* makes the matching "ungreedy", in that regex's normally try to match the largest string possible, which is why your pattern doesn't stop after it hits the first ddd, and this tells the regex engine to stop after it hits the first case of ddd.