{"record":{"id":"927f24584b112ba9","repo":"caddyserver/caddy","slug":"invalid-regexp-name-must-contain-only-word-charac","errorCode":null,"errorMessage":"invalid regexp name (must contain only word characters): %s","messagePattern":"invalid regexp name \\(must contain only word characters\\): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/matchers.go","lineNumber":1601,"sourceCode":"\tPattern string `json:\"pattern\"`\n\n\tcompiled *regexp.Regexp\n}\n\n// Provision compiles the regular expression.\nfunc (mre *MatchRegexp) Provision(caddy.Context) error {\n\tre, err := regexp.Compile(mre.Pattern)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"compiling matcher regexp %s: %v\", mre.Pattern, err)\n\t}\n\tmre.compiled = re\n\treturn nil\n}\n\n// Validate ensures mre is set up correctly.\nfunc (mre *MatchRegexp) Validate() error {\n\tif mre.Name != \"\" && !wordRE.MatchString(mre.Name) {\n\t\treturn fmt.Errorf(\"invalid regexp name (must contain only word characters): %s\", mre.Name)\n\t}\n\treturn nil\n}\n\n// Match returns true if input matches the compiled regular\n// expression in mre. It sets values on the replacer repl\n// associated with capture groups, using the given scope\n// (namespace).\nfunc (mre *MatchRegexp) Match(input string, repl *caddy.Replacer) bool {\n\tmatches := mre.compiled.FindStringSubmatch(input)\n\tif matches == nil {\n\t\treturn false\n\t}\n\n\t// save all capture groups, first by index\n\tfor i, match := range matches {\n\t\tkeySuffix := \".\" + strconv.Itoa(i)\n\t\tif mre.Name != \"\" {","sourceCodeStart":1583,"sourceCodeEnd":1619,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/matchers.go#L1583-L1619","documentation":"MatchRegexp.Validate requires the optional `name` of a regexp matcher to match \\w+ (letters, digits, underscore only, non-empty). The name becomes the namespace for {http.regexp.<name>.captures...} placeholders, so characters like '.', '-', '/' or spaces would break placeholder keys and are rejected.","triggerScenarios":"header_regexp foo.bar UserAgent ... (dot), path_regexp my-name ... (hyphen), name with a space or slash, or an empty-after-trimming name.","commonSituations":"Naming capture groups after hostnames or URLs (myapp.example.com); kebab-case habit from other directives; JSON configs where the name field is auto-filled from an ID.","solutions":["Rename to word characters only: use v1 not v.1, my_name not my-name.","Keep the name short and unique per matcher if you rely on its placeholders.","If placeholders are not used, you may omit the name entirely."],"exampleFix":"// before (Caddyfile)\n@m path_regexp my-name ^/x(.*)\n\n// after\n@m path_regexp my_name ^/x(.*)","handlingStrategy":"validation","validationCode":"import \"regexp\"\n\nvar wordRE = regexp.MustCompile(`^\\w+$`)\n\nfunc validRegexpName(name string) bool {\n\treturn name == \"\" || wordRE.MatchString(name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name regexp matchers with [A-Za-z0-9_] only.","Use snake_case, not kebab-case or dotted names.","Omit the name if you never read its placeholders."],"tags":["caddy","config","regex","naming","placeholder"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}