In terms of coding style, is it considered correct to remove the caret (^) and dollar sign ($) symbols when using regular expressions to extract email addresses in PHP?

When using regular expressions to extract email addresses in PHP, it is not necessary to include the caret (^) and dollar sign ($) symbols at the beginning and end of the pattern. These symbols are used to match the start and end of a line, which is not needed when extracting email addresses from a block of text. By removing these symbols, the regex pattern will be more flexible and able to match email addresses within the text.

$text = "Sample text with email addresses user1@example.com and user2@example.com";
$pattern = '/\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b/';
preg_match_all($pattern, $text, $matches);

foreach($matches[0] as $email) {
    echo $email . "\n";
}