REGEXVAULTv2.0
Security/Network Security
Verified Safe

CVE Identifier Regex for Python

/^CVE-(19[6-9][0-9]|20[0-9]{2})-([0-9]{4,7})$/i

What this pattern does

This page provides a well-structured, multi-part regular expression for matching cve identifier, ported and verified for Python. In security-sensitive code, using an unverified regex can open the door to both false positives and denial-of-service attacks. 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
# CVE Identifier
# ReDoS-safe | RegexVault — Security > Network Security

import re

cve_identifier_pattern = re.compile(r'^CVE-(19[6-9][0-9]|20[0-9]{2})-([0-9]{4,7})$')

def validate_cve_identifier(value: str) -> bool:
    return bool(cve_identifier_pattern.fullmatch(value))

# Example
print(validate_cve_identifier("CVE-2021-44228"))  # True

Test Cases

Matches (Valid)
Rejects (Invalid)
CVE-2021-44228CVE-2021-123
CVE-2024-0001CVE-21-44228
CVE-2014-0160CWE-2021-44228
CVE-1999-0001CVE-2021-1234ABCD
CVE-2023-1234567

When to use this pattern

This pattern is drawn from the Security > Network Security 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

NNNNN can be longer than 4 digits for high-volume years (2023 had over 28000 CVEs). Ensure your pattern handles 5-7 digit sequences. CVE IDs with 7 digits appeared starting around 2014.

Technical Notes

CVE format: CVE-YYYY-NNNNN where YYYY is 1960-present year and NNNNN is at least 4 digits. Notable examples: CVE-2021-44228 (Log4Shell), CVE-2014-0160 (Heartbleed), CVE-2017-5638 (Apache Struts/Equifax breach). Year range starts 1960 (earliest MITRE entry).

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