DD
DevDash

Regex for CVE Identifier

Regex Pattern

^CVE-\d{4}-\d{4,}$

Common Vulnerabilities and Exposures (CVE) ID

Quick Answer

The regex pattern for cve identifier is `^CVE-\d{4}-\d{4,}$`. Common Vulnerabilities and Exposures (CVE) ID. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.

Test Examples

InputResult
CVE-2021-44228✓ Matches
CVE-2023-12345✓ Matches
CVE-2024-0001✓ Matches
CVE-2021✗ No match
CVE-21-44228✗ No match
cve-2021-44228✗ No match

Code Examples

javascript

const regex = /^CVE-\d{4}-\d{4,}$/;
const isValid = regex.test(value);

python

import re
pattern = r'^CVE-\d{4}-\d{4,}$'
if re.match(pattern, value):
    print("valid")

ruby

pattern = /^CVE-\d{4}-\d{4,}$/
if value =~ pattern
  puts "valid"
end

php

if (preg_match('/^CVE-\d{4}-\d{4,}$/', $value)) {
    echo "valid";
}

java

String pattern = "^CVE-\\d{4}-\\d{4,}$";
boolean isValid = value.matches(pattern);

Frequently Asked Questions

Related Regex Patterns

Want API access + no ads? Pro coming soon.