REGEXVAULTv2.0
Security/Network Security
Verified Safe

CVE Identifier Regex for Go

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

Go Implementation

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

package validation

import "regexp"

var cveIdentifierRe = regexp.MustCompile(`^CVE-(19[6-9][0-9]|20[0-9]{2})-([0-9]{4,7})$`)

func ValidateCveIdentifier(s string) bool {
    return cveIdentifierRe.MatchString(s)
}

// Example
// fmt.Println(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 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

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