How can regular expressions (regex) be used effectively in PHP to extract data from text strings like in the given example?

Regular expressions in PHP can be used effectively to extract specific data from text strings by defining patterns that match the desired content. In the given example, we can use regex to extract email addresses from a text string. By using the `preg_match_all` function in PHP along with a regex pattern for email addresses, we can easily extract all email addresses present in the text.

$text = "Contact us at email@example.com or support@example.com for assistance.";
$pattern = '/[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/';
preg_match_all($pattern, $text, $matches);

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