How can regular expressions be used to extract specific values from HTML tags in PHP?

Regular expressions can be used in PHP to extract specific values from HTML tags by matching patterns within the HTML code. By using preg_match() or preg_match_all() functions in PHP, you can search for and extract the desired values based on the specified regular expression pattern.

$html = '<div class="example">Hello, World!</div>';
$pattern = '/<div class="example">(.*?)<\/div>/s';
preg_match($pattern, $html, $matches);
$value = $matches[1];
echo $value; // Output: Hello, World!