{"record":{"id":"9aa57170023abc99","repo":"projectdiscovery/nuclei","slug":"could-not-compile-regex-s","errorCode":null,"errorMessage":"could not compile regex: %s","messagePattern":"could not compile regex: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/operators/extractors/compile.go","lineNumber":35,"sourceCode":"\tcomputedType, err := toExtractorTypes(e.GetType().String())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unknown extractor type specified: %s\", e.Type)\n\t}\n\te.extractorType = computedType\n\n\tif e.extractorType == RegexExtractor && e.RegexGroup < 0 {\n\t\treturn fmt.Errorf(\"regex extractor group must be >= 0, got %d\", e.RegexGroup)\n\t}\n\n\t// Compile the regexes\n\tfor _, regex := range e.Regex {\n\t\tif cached, err := cache.Regex().GetIFPresent(regex); err == nil && cached != nil {\n\t\t\te.regexCompiled = append(e.regexCompiled, cached)\n\t\t\tcontinue\n\t\t}\n\t\tcompiled, err := regexp.Compile(regex)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not compile regex: %s\", regex)\n\t\t}\n\t\t_ = cache.Regex().Set(regex, compiled)\n\t\te.regexCompiled = append(e.regexCompiled, compiled)\n\t}\n\tfor i, kval := range e.KVal {\n\t\te.KVal[i] = strings.ToLower(kval)\n\t}\n\n\tfor _, query := range e.JSON {\n\t\tquery, err := gojq.Parse(query)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not parse json: %s\", query)\n\t\t}\n\t\tcompiled, err := gojq.Compile(query)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not compile json: %s\", query)\n\t\t}\n\t\te.jsonCompiled = append(e.jsonCompiled, compiled)","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/operators/extractors/compile.go#L17-L53","documentation":"Template compilation error from Extractor.CompileExtractors (pkg/operators/extractors/compile.go:35). Each entry of the extractor's `regex:` list is compiled with the standard library regexp.Compile (after consulting the shared regex cache). A pattern Go's RE2 engine cannot parse returns this error naming the offending pattern.","triggerScenarios":"A regex using constructs RE2 rejects: backreferences (\\1), lookahead/lookbehind ((?=...), (?<=...)), arbitrary {n,m} repetition on unsupported constructs, or simple syntax errors like an unmatched ')' or '['.","commonSituations":"Porting PCRE patterns from Python/Perl/OWASP rules directly into a template; escaping mistakes in YAML single vs double quotes (e.g. '\\d' vs \"\\d\"); truncation of long patterns during copy-paste.","solutions":["Test the pattern standalone with Go regexp: `go run` a one-liner or use an RE2-compatible tester (e.g. regex101 with 'golang' flavor)","Remove PCRE-only features: rewrite backreferences with capture + kval/dsl, lookaheads with separate matchers or a chained request","Fix YAML quoting so backslashes survive: prefer single-quoted YAML strings with \\d, \\s literally","Validate the template with `nuclei -validate -t <file>` which surfaces the exact failing regex"],"exampleFix":"# before (RE2 rejects backreference)\nregex:\n  - '(user|admin)-\\1'\n# after\nregex:\n  - 'user-user|admin-admin'","handlingStrategy":"validation","validationCode":"import \"regexp\"\n\nfor _, r := range ex.Regex {\n\tif _, err := regexp.Compile(r); err != nil {\n\t\treturn fmt.Errorf(\"bad extractor regex %q: %w\", r, err)\n\t}\n}","typeGuard":"func isRE2Compatible(pattern string) bool { _, err := regexp.Compile(pattern); return err == nil }","tryCatchPattern":"if err := ex.CompileExtractors(); err != nil {\n\tif strings.Contains(err.Error(), \"could not compile regex\") {\n\t\t// extract pattern from message, report with template path\n\t}\n}","preventionTips":["Test patterns in regex101 with the 'golang' flavor before committing","Avoid backreferences/lookarounds; redesign as multi-matcher or chained requests","Use single-quoted YAML strings to preserve backslashes"],"tags":["extractor","regex","re2","template","compile-time"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}