I want
ereg ($rat, $dog, $cat)
to become
preg_match (\'#\'.$rat.\'#\', $dog, $cat)
To achieve this, I did
~ ross$ echo 'ereg ($rat, $dog, $cat)' | sed -e "s/.*(\([^,]*\),\([^,]*\),\([^)]*\))/preg_match ('#'.\1.'#', \2, \3)/" preg_match ('#'.$rat.'#', $dog, $cat)