I've got a website in PHP which utilizes multiple MySQL tables and switches together using the mysql_choose_db function.

    DB1 (table1, table2, table3)
    DB2 (table1, table2)

The ultimate hosting regrettably supports just one single database. And So I considered a method which replaces the mysql_choose_db functions having a custom mysql_switch_prefix function which stores a string that'll be used like a prefix for those table names in following query's.

    DB (DB1_table1, DB1_table2, DB1_table3, DB2_table1, DB2_table2)

Next I'll make use of a custom mysql_query function that replaces all table names with table names prefixed using the 'db_prefix' variable.

    SELECT * FROM `table1` -> SELECT * FROM `DB1_table1`

It is possible to way (or perhaps a regular expression) to exchange all table names inside a SQL statement by table names prefixed having a variable?

You are able to query the table names and set them right into a PHP array.

$result = mysql_query("SHOW TABLES FROM [DB name]")
while($tableNames = mysql_fetch_row($result)){...}

Then produce a loop, and make a move such as this:

mysql_query("RENAME TABLE" . $tableNames[$i] . "TO [prefix]" . tableNames[$i]);

Here's the MySQL documentation, for that "Relabel..." query.