{"record":{"id":"75345af429604178","repo":"projectdiscovery/katana","slug":"could-not-compile-regex-s-s","errorCode":null,"errorMessage":"could not compile regex %s: %s","messagePattern":"could not compile regex (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/utils/scope/scope.go","lineNumber":46,"sourceCode":"\tcustomDNSScopeField\n)\n\nvar stringToDNSScopeField = map[string]dnsScopeField{\n\t\"dn\":   dnDnsScopeField,\n\t\"rdn\":  rdnDnsScopeField,\n\t\"fqdn\": fqdnDNSScopeField,\n}\n\n// NewManager returns a new scope manager for crawling\nfunc NewManager(inScope, outOfScope []string, fieldScope string, noScope bool) (*Manager, error) {\n\tmanager := &Manager{\n\t\tnoScope: noScope,\n\t}\n\n\tif scopeValue, ok := stringToDNSScopeField[fieldScope]; !ok {\n\t\tmanager.fieldScope = customDNSScopeField\n\t\tif compiled, err := regexp.Compile(fieldScope); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not compile regex %s: %s\", fieldScope, err)\n\t\t} else {\n\t\t\tmanager.fieldScopePattern = compiled\n\t\t}\n\t} else {\n\t\tmanager.fieldScope = scopeValue\n\t}\n\tfor _, regex := range inScope {\n\t\tif compiled, err := regexp.Compile(regex); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not compile regex %s: %s\", regex, err)\n\t\t} else {\n\t\t\tmanager.inScope = append(manager.inScope, compiled)\n\t\t}\n\t}\n\tfor _, regex := range outOfScope {\n\t\tif compiled, err := regexp.Compile(regex); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"could not compile regex %s: %s\", regex, err)\n\t\t} else {\n\t\t\tmanager.outOfScope = append(manager.outOfScope, compiled)","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/projectdiscovery/katana/blob/e3e742739c3746f085943ce918fb4e2b8daf6fe6/pkg/utils/scope/scope.go#L28-L64","documentation":"NewManager validates the field-scope value against known DNS scope fields; if it isn't a predefined field, it is treated as a custom regex and compiled. regexp.Compile failing on a malformed pattern produces this error and aborts manager creation. The pattern text and the regexp error are both embedded in the message.","triggerScenarios":"Calling scope.NewManager(fieldScope, inScope, outOfScope) with a fieldScope string that is neither a known DNS scope field (e.g., \"domain\", \"full\") nor a valid Go regexp — e.g., \"[a-z\" or \"*.example.com\".","commonSituations":"Reading scope config from YAML/flags where the user confused glob syntax with regex (\"*.corp.local\"); forgetting Go regexp is RE2 (no lookaheads like (?!...)); accidental shell or JSON escaping mangling backslashes.","solutions":["Fix the fieldScope regex syntax — test it with https://regex101.com (Go flavor) or regexp.Compile in a scratch program.","Replace glob-style patterns (*.) with regex equivalents (e.g., \"^([a-z0-9-]+\\\\.)*corp\\\\.local$\").","Remove unsupported RE2 constructs such as lookaheads/lookbehinds and backreferences.","Use a predefined fieldScope value (a known DNS scope field) instead of a custom regex if one matches your intent."],"exampleFix":"// before\nmgr, err := scope.NewManager(\"*.corp.local\", nil, nil) // glob, not regex\n// after\nmgr, err := scope.NewManager(\"^([a-z0-9-]+\\\\.)*corp\\\\.local$\", nil, nil)","handlingStrategy":"validation","validationCode":"if _, err := regexp.Compile(fieldScope); err != nil {\n    return fmt.Errorf(\"invalid field scope pattern %q: %w\", fieldScope, err)\n}","typeGuard":"func isValidRegex(s string) bool {\n    _, err := regexp.Compile(s)\n    return err == nil\n}","tryCatchPattern":"mgr, err := scope.NewManager(fieldScope, inScope, outOfScope)\nif err != nil {\n    if strings.Contains(err.Error(), \"could not compile regex\") {\n        // surface the pattern to the user with config file/line context before exiting\n    }\n}","preventionTips":["Test scope patterns with the Go regexp package or regex101 (Go flavor) before deploying config.","Remember RE2 has no lookaheads, lookbehinds, or backreferences.","Convert glob-style patterns to regex explicitly, don't pass globs where regex is expected."],"tags":["regex","scope","config"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"e3e742739c3746f085943ce918fb4e2b8daf6fe6","analyzedAt":"2026-09-03T14:55:13.248Z","contentChangedAt":"2026-09-03T14:55:13.248Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}