(
isn't a special character in sed regular expressions. You don't need to escape it.
sed -e 's/jQuery(function/head.ready(function/g'
[(]
in a regex means a character set containing just one element, (
. It's a convoluted way of writing (
.
[(]
in replacement text means the three characters [(]
. Brackets have no special meaning in replacement text.
You can avoid repeating the function name if you like, by putting it in a group. Groups are delimited by backslash-parenthesis.
sed -e 's/jQuery(\(function\)/head.ready(\1/g'
Beware that your replacement will also affect jQuery(functionwithsuffix
. The easy way to avoid this is to use a tool that understands extended Perl regular expressions, so you can use (?![^A-Za-z0-9_])
at the end of the search string, meaning “followed by something that isn't an alphanumeric character”. Note that in Perl regular expressions, (
is special, you need to prefix it with a backslash.
perl -pe 's/jQuery\(function(?![^A-Za-z0-9_])/head.ready(function/g'
perl -pe 's/jQuery\((function)(?![^A-Za-z0-9_])/head.ready($1/g'