{"record":{"id":"efa16596a42f9046","repo":"crowdsecurity/crowdsec","slug":"could-not-compile-regexp-s-w","errorCode":null,"errorMessage":"could not compile regexp %s: %w","messagePattern":"could not compile regexp (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/acquisition/modules/file/config.go","lineNumber":66,"sourceCode":"\t\ts.config.Filenames = append(s.config.Filenames, s.config.Filename)\n\t}\n\n\tif len(s.config.Filenames) == 0 {\n\t\treturn errors.New(\"no filename or filenames configuration provided\")\n\t}\n\n\tif s.config.Mode == \"\" {\n\t\ts.config.Mode = configuration.TAIL_MODE\n\t}\n\n\tif s.config.Mode != configuration.CAT_MODE && s.config.Mode != configuration.TAIL_MODE {\n\t\treturn fmt.Errorf(\"unsupported mode %s for file source\", s.config.Mode)\n\t}\n\n\tfor _, exclude := range s.config.ExcludeRegexps {\n\t\tre, err := regexp.Compile(exclude)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"could not compile regexp %s: %w\", exclude, err)\n\t\t}\n\n\t\ts.exclude_regexps = append(s.exclude_regexps, re)\n\t}\n\n\treturn nil\n}\n\nfunc (s *Source) Configure(_ context.Context, yamlConfig []byte, logger *log.Entry, metricsLevel metrics.AcquisitionMetricsLevel) error {\n\ts.logger = logger\n\ts.metricsLevel = metricsLevel\n\n\terr := s.UnmarshalConfig(yamlConfig)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ts.watchedDirectories = make(map[string]bool)","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/crowdsecurity/crowdsec/blob/909b5157986a2b2c2163300fdaef5ed01289f7d2/pkg/acquisition/modules/file/config.go#L48-L84","documentation":"UnmarshalConfig compiles each entry of exclude_regexps with Go's regexp.Compile; an invalid pattern returns \"could not compile regexp %s: %w\". Go RE2 syntax differs from PCRE, so patterns valid elsewhere can fail here.","triggerScenarios":"exclude_regexps entries containing invalid RE2 syntax: dangling quantifiers (`*foo`), unmatched `(` or `[`, invalid escape sequences like `\\d` is fine but `\\p{...}` typos or `(?<=...)` lookbehinds are rejected by RE2.","commonSituations":"Copying PCRE lookbehind/lookahead patterns that RE2 doesn't support; quoting issues in YAML leaving literal backslashes; hand-written patterns with an unbalanced bracket; patterns intended for filepath matching (globs) pasted as regexps.","solutions":["Validate the pattern with Go semantics: `go run` a snippet with regexp.Compile, or test at https://regex101.com with the Golang flavor.","Fix unbalanced delimiters/dangling quantifiers reported in the wrapped error.","Replace unsupported PCRE constructs (lookbehinds, backreferences) with RE2-compatible alternatives (e.g. multiple exclude_regexps entries).","Quote backslashes properly in YAML (single quotes) so `\\.` reaches the compiler intact."],"exampleFix":"// before\nexclude_regexps:\n  - '(?<=error)denied'   # RE2 has no lookbehind\n// after\nexclude_regexps:\n  - 'error.*denied'","handlingStrategy":"validation","validationCode":"// Go: compile-check every exclude pattern before writing config\nfor _, pat := range cfg.ExcludeRegexps {\n\tif _, err := regexp.Compile(pat); err != nil {\n\t\treturn fmt.Errorf(\"exclude_regexps entry invalid: %w\", err)\n\t}\n}","typeGuard":null,"tryCatchPattern":"if err := src.UnmarshalConfig(cfgYAML); err != nil {\n\tvar reErr *regexp.SyntaxError\n\tif errors.As(err, &reErr) || strings.Contains(err.Error(), \"could not compile regexp\") {\n\t\t// fix the named pattern (RE2 flavor), then retry\n\t}\n}","preventionTips":["Test patterns with the Golang (RE2) flavor on regex101 or `go test`.","Avoid PCRE-only features: lookbehinds, backreferences, atomic groups.","Single-quote YAML strings containing backslashes to keep escapes intact.","Keep exclude_regexps simple — prefer anchored literal matches over complex patterns."],"tags":["regexp","config","file-source"],"backgroundTag":"invalid-regex-pattern","analyzedSha":"909b5157986a2b2c2163300fdaef5ed01289f7d2","analyzedAt":"2026-09-06T12:27:26.012Z","contentChangedAt":"2026-09-06T12:27:26.012Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}