What are the advantages and disadvantages of using preg_replace() in PHP for string manipulation tasks?

When using preg_replace() in PHP for string manipulation tasks, one advantage is that it allows for more complex pattern matching and replacing compared to other string manipulation functions. However, a disadvantage is that it can be slower and less efficient than simpler string manipulation functions like str_replace() for basic replacements.

// Example of using preg_replace() to replace all occurrences of a word with another word in a string
$text = "Hello, world! This is a test string.";
$pattern = "/test/";
$replacement = "example";

$new_text = preg_replace($pattern, $replacement, $text);

echo $new_text;