Are there any potential pitfalls to be aware of when using regular expressions in PHP to extract numbers from a string?

One potential pitfall when using regular expressions in PHP to extract numbers from a string is that the expression may not handle certain edge cases, such as numbers with commas or decimals. To overcome this, you can use a more specific regular expression pattern that accounts for these variations.

$string = "The price is $25.99";
$pattern = '/\d+(\.\d+)?/';
preg_match($pattern, $string, $matches);
$number = $matches[0];
echo $number;