What potential pitfalls should be considered when using preg_replace in PHP to filter out non-numeric characters from a string?

When using preg_replace in PHP to filter out non-numeric characters from a string, it's important to consider that the regular expression used may inadvertently remove valid numeric characters or alter the string in unexpected ways. To avoid this, it's recommended to use a more specific regular expression pattern that only targets non-numeric characters. Additionally, it's important to test the implementation thoroughly to ensure that it behaves as expected with different input strings.

$string = "123abc456";
$filtered_string = preg_replace("/[^0-9]/", "", $string);
echo $filtered_string;