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

Height (Metric and Imperial) Regex for Go

/^(?:(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 Go. 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 Go project — whether you're validating in a Gin handler, a gRPC service, or a command-line tool.

Go Implementation

Go
// Height (Metric and Imperial)
// ReDoS-safe | RegexVault — Identity & PII > Biometric & Physical

package validation

import "regexp"

var heightMetricAndImperialRe = regexp.MustCompile(`^(?:(1[0-9]{2}|2[0-5][0-9])\s?cm)|(?:([1-8])'(?:\s?(?:0|[1-9]|1[01])"?)??)$`)

func ValidateHeightMetricAndImperial(s string) bool {
    return heightMetricAndImperialRe.MatchString(s)
}

// Example
// fmt.Println(ValidateHeightMetricAndImperial("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 Go developers because Go's RE2 engine is inherently safe from catastrophic backtracking, but this pattern has been additionally verified for correctness. 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