I am upgrading my PHP scripts to use mysqli and it necessitates changing thousands of lines where the variables have exchanged position. For example:
The non-escaped parentheses in the regular expression create capture groups, and
$2 in the replacement pick up what was matched by them.
This will only work for statements like you've posted, where the query is a variable, since
\$\w+ just matches a variable name. It won't work if you have literal strings like
mysql_query("SELECT ...", $db);