What additional considerations should be made when filtering IP addresses in PHP using preg_match?

When filtering IP addresses in PHP using preg_match, it's important to consider the format of the IP address and ensure that it matches the standard IPv4 or IPv6 formats. Additionally, you may want to validate that the IP address is within a certain range or belongs to a specific subnet.

$ip_address = "192.168.1.1";

if (preg_match("/^([0-9]{1,3}\.){3}[0-9]{1,3}$/", $ip_address)) {
    echo "Valid IP address: " . $ip_address;
} else {
    echo "Invalid IP address: " . $ip_address;
}