REGEXVAULTv2.0
Identity & PII/Digital Identity
Verified Safe

IPv4 Address (as PII identifier) Regex for Python

/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])$/

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching ipv4 address (as pii identifier), ported and verified for Python. Identity and credential patterns need both correctness and safety, since they're frequent targets for adversarial input. The snippet below is ready to drop into your Python project — whether you're validating in a Django view, a FastAPI endpoint, or a standalone data processing script.

Python Implementation

Python
# IPv4 Address (as PII identifier)
# ReDoS-safe | RegexVault — Identity & PII > Digital Identity

import re

ipv4_address_as_pii_identifier_pattern = re.compile(r'^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])$')

def validate_ipv4_address_as_pii_identifier(value: str) -> bool:
    return bool(ipv4_address_as_pii_identifier_pattern.fullmatch(value))

# Example
print(validate_ipv4_address_as_pii_identifier("192.168.1.1"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
192.168.1.1192.168.1.256
10.0.0.1192.168.1
8.8.8.8192.168.1.1.1
255.255.255.255192.168.01.1
0.0.0.0

When to use this pattern

This pattern is drawn from the Identity & PII > Digital Identity category and carries a ReDoS-safe certification. That matters for Python developers because particularly important in Python web servers where CPU-bound regex operations can stall concurrent request handling. RegexVault audits patterns against known backtracking attack vectors, ensuring you have the necessary context before using this regex in a high-stakes production environment.

Common Pitfalls

Anonymizing IPs by zeroing the last octet (192.168.1.0 from 192.168.1.50) is a common technique for analytics. GDPR Article 25 (Privacy by Design) recommends this for non-essential logging.

Technical Notes

Under GDPR (C-582/14, Breyer v Germany), IP addresses can constitute personal data when the controller has the legal means to identify the individual. Dynamic IPs assigned by ISPs are personal data. Log files containing IP addresses must comply with GDPR retention requirements.

Have a pattern that belongs in the vault?

Submit it for review — community-verified patterns get credited to your GitHub handle. Free submissions join the queue. Priority review available for $15.

Submit a Pattern