REGEXVAULTv2.0
Identity & PII/Biometric & Physical
Verified Safe

Height (Metric and Imperial) Regex for Python

/^(?:(1[0-9]{2}|2[0-5][0-9])\s?cm)|(?:([1-8])'(?:\s?(?:0|[1-9]|1[01])"?)??)$/i

What this pattern does

This page provides a comprehensive, battle-tested regular expression for matching height (metric and imperial), 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
# Height (Metric and Imperial)
# ReDoS-safe | RegexVault — Identity & PII > Biometric & Physical

import re

height_metric_and_imperial_pattern = re.compile(r'^(?:(1[0-9]{2}|2[0-5][0-9])\s?cm)|(?:([1-8])'(?:\s?(?:0|[1-9]|1[01])"?)??)$')

def validate_height_metric_and_imperial(value: str) -> bool:
    return bool(height_metric_and_imperial_pattern.fullmatch(value))

# Example
print(validate_height_metric_and_imperial("175cm"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
175cm99cm
175 cm260cm
6'2"9'
5'10"5'13"
5'5ft 10in
200cmcm175
183 CM

When to use this pattern

This pattern is drawn from the Identity & PII > Biometric & Physical 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

Height alone is rarely identifying. Combined with name, DOB, and other attributes, it becomes part of a biometric profile. The GDPR biometric data category applies when height is processed to uniquely identify a person.

Technical Notes

Metric range: 100-259 cm (practical human height range). Imperial: 1-8 feet, 0-11 inches. Height is body measurement data — classified as sensitive personal data in some jurisdictions (biometric data under GDPR if combined with other identifiers).

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