$re = '/\$\(\s*?["\']([^"\']+?)["\']\s*?\)\.live\(\s*?["\']([^"\']+?)["\'][^\(]+?\(/';
$str = '$(".delete_package").live("click", function() {
// this is a test
}
$(".add_package").live( "mouseout", function(e) {
// this is a test
}
$( ".ccc_package" ).live( "mouseover", function(e, x) {
// this is a with var e + x
}
';
$subst = "$(document.body).on(\"$2\", \"$1\", function(";
$result = preg_replace($re, $subst, $str);
echo "The result of the substitution is ".$result;
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for PHP, please visit: http://php.net/manual/en/ref.pcre.php