REGEXVAULTv2.0
Security/Network Security
Verified Safe

CVE Identifier Regex for JavaScript

/^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 JavaScript. 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 JavaScript project — whether you're validating in an Express middleware, a Next.js API route, or a client-side form.

Javascript Implementation

Javascript
// CVE Identifier
// ReDoS-safe | RegexVault — Security > Network Security

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

function validateCveIdentifier(input: string): boolean {
  return cveIdentifierRegex.test(input);
}

// Example
console.log(validateCveIdentifier("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 JavaScript developers because especially critical in long-running Node.js event loops where a ReDoS vulnerability can block the entire process. 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