What are some common issues encountered when using preg_match_all in PHP to extract specific values from a string?

One common issue when using preg_match_all in PHP to extract specific values from a string is not capturing the desired values correctly due to incorrect regular expressions. To solve this, ensure that the regular expression pattern accurately matches the desired values and uses proper capturing groups.

$string = "The price of the product is $50. The discount is 20%.";
$pattern = '/\$([0-9.]+)%/'; // Regular expression pattern to extract the discount percentage value

preg_match_all($pattern, $string, $matches);

print_r($matches[1]); // Output: Array ( [0] => 20 )