REGEXVAULTv2.0
Security/Network Security
Verified Safe

CVE Identifier Regex for PHP

/^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 PHP. 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 PHP project — whether you're validating in a Laravel validator, a WordPress plugin, or a standalone PHP script.

Php Implementation

Php
<?php
// CVE Identifier
// ReDoS-safe | RegexVault — Security > Network Security

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

function validate_cve_identifier(string $input): bool {
    return (bool) preg_match(CVE_IDENTIFIER_PATTERN, $input);
}

// Example
var_dump(validate_cve_identifier("CVE-2021-44228")); // bool(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 PHP developers because especially relevant in PHP where PCRE backtracking limits can trigger silent failures on malicious input. 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