Per quello che vuoi fare non credo che occorino le espressioni regolari.
Forse non ho capito bene il tuo problema ma comunque ti allego uno script.
Codice PHP:
<?
function prepareStr (&$item1) {
$item1 = addslashes($item1);
$item1 = "'$item1'";
}
$str_insert = "INSERT INTO tabella (#) VALUES (@)";
$arrFields = array();
$arrValues = array();
//
$arrFields[0] = 'id';
$arrFields[1] = 'nome';
$arrFields[2] = 'cognome';
//
$arrValues[0] = "120";
$arrValues[1] = "umberto";
$arrValues[2] = "dell'aquila";
//
$str_insert = str_replace("#",implode(',',$arrFields),$str_insert);
array_walk ($arrValues, 'prepareStr');
$str_insert = str_replace("@",implode(',',$arrValues),$str_insert);
print "1 -> $str_insert";
print "
";
$arrFields = array();
$arrValues = array();
//
$arrFields[0] = 'id';
$arrFields[1] = 'nome';
$arrFields[2] = 'cognome';
//
$arrValues[0] = "120";
$arrValues[1] = "umberto";
$arrValues[2] = "dell'aquila";
//
$fieldList = implode(',',$arrFields);
array_walk ($arrValues, 'prepareStr');
$dataList = implode(',',$arrValues);
$str_insert = "INSERT INTO tabella ($fieldList) VALUES ($dataList)";
print "2 -> $str_insert";
?>