Here's one example...
// regexp that matches (most) valid PHP variable names
$php_var = '[a-zA-Z_][a-zA-Z0-9_]*';
// find and replace patterns
$find = 'ereg(i?) *\( *(["\'])(.*)["\'], *(\$' . $php_var . ')(, *\$' . $php_var . ')? *)';
$fixt = 'preg_match(\2/\3/\1\2, \4\5)';
Example usage:
$data = 'eregi(\'foo?\', $subject, $matches)';
echo eregi_replace($find, $fixt, $data) . "\n";
$data = 'ereg( "([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $subject )';
echo eregi_replace($find, $fixt, $data) . "\n";
output:
Deprecated: Function eregi_replace() is deprecated in <file> on line <line>
preg_match('/foo/i', $subject, $matches)
Deprecated: Function eregi_replace() is deprecated in <file> on line <line>
preg_match("/([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})/", $subject)