What are potential pitfalls when using regular expressions as delimiters in preg_replace?

Using regular expressions as delimiters in preg_replace can lead to unexpected results if the delimiters are not properly escaped. To avoid this issue, it is recommended to use a different delimiter character that is not present in the regular expression pattern. This can prevent conflicts and ensure the pattern is interpreted correctly.

// Example of using a different delimiter to avoid conflicts
$string = "Hello, World!";
$pattern = "/,/";
$replacement = "-";
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string; // Output: Hello- World!