REGEXVAULTv2.0
Identity & PII/Health Identifiers
Verified Safe

Australian Medicare Number Regex for Python

/^([2-6][0-9]{9})(?:\s*([1-9]))?$/

What this pattern does

This page provides a well-structured, multi-part regular expression for matching australian medicare number, 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
# Australian Medicare Number
# ReDoS-safe | RegexVault — Identity & PII > Health Identifiers

import re

australian_medicare_number_pattern = re.compile(r'^([2-6][0-9]{9})(?:\s*([1-9]))?$')

def validate_australian_medicare_number(value: str) -> bool:
    return bool(australian_medicare_number_pattern.fullmatch(value))

# Example
print(validate_australian_medicare_number("2123456701"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
21234567011123456701
2123456701 17123456701
6999999991212345670
2123456701121234567010
2123456701A

When to use this pattern

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

The IRN distinguishes family members sharing a Medicare card. When storing, preserve both the 10-digit number and the IRN — the full reference is: XXXXXXXXXX/1 (where 1 is the cardholder, 2-9 are dependants).

Technical Notes

Australian Medicare numbers start with 2-6 (4=concessional). 10-digit number + 1-digit IRN (Individual Reference Number, 1-6, identifies individuals on a family card). Checksum: weighted sum of first 9 digits, compare to 10th. Services Australia assigns and validates.

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