Array replace patterns

Regular expresions with arrays

I had to sanitize a csv file, where a column could contain a separatoer character inside, for example:
field1;field2;fiel;d3;
field3 needs to be sanitized, it has a semicolon inside, see?
 
 
 
The idea is to create an array where the keys are the patterns, the values are desired the replacement string


 
        // Replace patterns array: separators between two double quotes
         $patterns = array (
            '/(\".*)(;)(.*\")/is' => '${1}${3}',     // semicolon
            '/(\".*)(\|)(.*\")/is' => '${1}${3}',    // pipe
            '/(\".*)(,)(.*\")/is' => '${1}${3}',     // comma
            '/(\".*)(\\t)(.*\")/is' => '${1}${3}',   // tab
            
            );
           
            
            $sanitized=(preg_replace(array_keys($patterns),array_values($patterns),$text));