mardi 4 août 2015

Replace all occurrences of PHP function name with SED

I have a PHP file with multiple calls of function my_function() and I want to replace it with blah_blah(), just rename the function name everywhere. I have also another_my_function() there which I don't wan't to be replaced.

Here I've created the regular expression:

[^\w\*]my_function\(

Which means that the prefix should be some special character, than function name with starting round bracket. I replace it in a folder so here we go:

find my_folder_name -type f -exec sed -i 's/[^\w\*]my_function(/blah_blah(/g' {} \;

Round bracket is not a special character for sed so we don't need to escape it. The problem is, I'm sure you noticed, that it will replace the function names including the prefix symbol [^\w\*].

How can I replace only the name of function?

Aucun commentaire:

Enregistrer un commentaire