I want
ereg ($rat, $dog, $cat)
to become
preg_match (\'#\'.$rat.\'#\', $dog, $cat)
To achieve this, I did
Note: This also works if you have multiple instances of ereg ($rat, $dog, $cat)
on the same line whereas other answers do not:
$ echo 'ereg ($rat, $dog, $cat)' | sed "s/ereg\([^(]*\)(\([^,]*\),\([^)]*)\)/preg_match\1('#'.\2.'#',\3/g"
preg_match ('#'.$rat.'#', $dog, $cat)
$ echo 'ereg ($rat, $dog, $cat) ereg ($rat, $dog, $cat)' | sed "s/ereg\([^(]*\)(\([^,]*\),\([^)]*)\)/preg_match\1('#'.\2.'#',\3/g"
preg_match ('#'.$rat.'#', $dog, $cat) preg_match ('#'.$rat.'#', $dog, $cat)