In what scenarios would using regular expressions be a better approach than explode() for extracting text in PHP?

Regular expressions would be a better approach than explode() for extracting text in PHP when the text pattern you are trying to extract is complex and cannot be easily defined by a single delimiter. Regular expressions offer more flexibility and power in defining patterns to match specific text structures. They are especially useful when dealing with variable-length delimiters or when you need to extract text based on certain conditions or rules.

$text = "Hello, my email is john.doe@example.com";
$pattern = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/';
preg_match($pattern, $text, $matches);
$email = $matches[0];
echo $email;