Actually, your code will print:
"This is a 7 andigit a 9."
I'm not familiar with the "classes" you mention, but I'm only conversant with two or three languages. They look slightly more like PCRE's, but your code doesn't seem to work with [man]preg_replace/man either, so I'm guessing it's some other convention outside PHP and friends.
This does work:
<?
echo ereg_replace("[0-9]", "digit", "This is a 7 and a 9.");
?>
"[:digit:]" works too, as POSIX requires. You'll need some PERL refugee to give you the equivalent PCRE syntax. π