Skip to content

Instantly share code, notes, and snippets.

@filewalkwithme
Last active April 19, 2018 04:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filewalkwithme/c66c797e3b1b874247273f6fc4e5a912 to your computer and use it in GitHub Desktop.
Save filewalkwithme/c66c797e3b1b874247273f6fc4e5a912 to your computer and use it in GitHub Desktop.
Extract CVE numbers from a target string
package main
import (
"fmt"
"regexp"
)
func main() {
// https://cve.mitre.org/cve/identifiers/tech-guidance.html#extraction_or_parsing
var cveRegex = regexp.MustCompile(`(?i)(CVE-\d{4}-(0\d{3}|[1-9]\d{3,}))`)
fmt.Println(cveRegex.FindAllString("Lorem ipsum CVE-2001-1234, dolor sit amet CVE-2002-4567, vel ea tale iriure deseruisse.", -1))
fmt.Println(cveRegex.FindAllString("Usu et simul alterum offendit. Mei eu nobis CVE-2003-8989invidunt patrioque.", -1))
fmt.Println(cveRegex.FindAllString("adam[23]", -1))
fmt.Println(cveRegex.FindAllString("eve[7]", -1))
fmt.Println(cveRegex.FindAllString("snakey", -1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment