What are the advantages of using preg_replace over str_replace when replacing strings in a JavaScript file using PHP?

When replacing strings in a JavaScript file using PHP, it is often more advantageous to use `preg_replace` over `str_replace` because `preg_replace` allows for more complex pattern matching using regular expressions. This can be useful when you need to replace strings based on specific patterns or conditions within the JavaScript file.

// Example code using preg_replace to replace strings in a JavaScript file
$javascript_file = file_get_contents('example.js');

// Replace all occurrences of 'old_string' with 'new_string'
$javascript_file = preg_replace('/old_string/', 'new_string', $javascript_file);

// Save the modified JavaScript file
file_put_contents('example.js', $javascript_file);