{"record":{"id":"a1ad898cc394b184","repo":"gofr-dev/gofr","slug":"regex-pattern-is-not-supported-use-mux-pa","errorCode":null,"errorMessage":"regex pattern '^...$' is not supported, use mux patterns instead","messagePattern":"regex pattern '\\^\\.\\.\\.\\$' is not supported, use mux patterns instead","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/rbac/config.go","lineNumber":31,"sourceCode":"\t\"go.opentelemetry.io/otel/trace\"\n\t\"gopkg.in/yaml.v3\"\n\n\t\"gofr.dev/pkg/gofr/container\"\n\t\"gofr.dev/pkg/gofr/datasource\"\n)\n\nvar (\n\t// errUnsupportedFormat is returned when the config file format is not supported.\n\terrUnsupportedFormat = errors.New(\"unsupported config file format\")\n\n\t// ErrEndpointMissingPermissions is returned when an endpoint doesn't specify requiredPermissions and is not public.\n\tErrEndpointMissingPermissions = errors.New(\"endpoint must specify requiredPermissions (or be public)\")\n\n\t// errWildcardPatternNotSupported is returned when a wildcard pattern is used.\n\terrWildcardPatternNotSupported = errors.New(\"wildcard pattern '/*' is not supported, use mux patterns instead\")\n\n\t// errRegexPatternNotSupported is returned when an old regex pattern is used.\n\terrRegexPatternNotSupported = errors.New(\"regex pattern '^...$' is not supported, use mux patterns instead\")\n\n\t// errRegexIndicatorNotSupported is returned when regex indicators are used outside variable constraints.\n\terrRegexIndicatorNotSupported = errors.New(\"regex pattern is not supported, use mux patterns instead\")\n)\n\n// RoleDefinition defines a role with its permissions and inheritance.\n// Pure config-based: only role->permission mapping is supported.\ntype RoleDefinition struct {\n\t// Name is the role name (required)\n\tName string `json:\"name\" yaml:\"name\"`\n\n\t// Permissions is a list of permissions for this role (format: \"resource:action\")\n\t// Example: [\"users:read\", \"users:write\"]\n\tPermissions []string `json:\"permissions,omitempty\" yaml:\"permissions,omitempty\"`\n\n\t// InheritsFrom lists roles this role inherits permissions from\n\t// Example: [\"viewer\"] - editor inherits all viewer permissions\n\tInheritsFrom []string `json:\"inheritsFrom,omitempty\" yaml:\"inheritsFrom,omitempty\"`","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/rbac/config.go#L13-L49","documentation":"errRegexPatternNotSupported is returned by checkRegexPattern when an RBAC endpoint path uses old regex-anchored syntax like '^/items/...$'. The RBAC layer migrated from regex matching to mux patterns, and anchored regex strings are explicitly rejected during config validation. The error exists to catch stale configs written for the pre-mux API.","triggerScenarios":"Configuring an endpoint as '^/users/[0-9]+$' or any pattern beginning with ^ and ending with $ in the RBAC permissions file; LoadPermissions validation calls checkRegexPattern and fails.","commonSituations":"Upgrading GoFr from an RBAC version that accepted regex paths; copy-pasting route patterns from regex-based routers; generated configs that still emit anchored regexes.","solutions":["Rewrite the pattern as a mux pattern, e.g. '/users/{id}' instead of '^/users/[0-9]+$'.","Remove '^' and '$' anchors — they are regex syntax and are rejected outright.","Use variable constraints supported by the mux instead of character classes if you need to restrict formats.","Update any config generators/scripts to emit mux patterns."],"exampleFix":"// before\n\"^/users/[0-9]+$\": {\"GET\": [\"admin\"]}\n// after\n\"/users/{id}\": {\"GET\": [\"admin\"]}","handlingStrategy":"validation","validationCode":"func isAnchoredRegex(pattern string) bool {\n\treturn strings.HasPrefix(pattern, \"^\") || strings.HasSuffix(pattern, \"$\")\n}\n// reject anchored regex patterns before loading RBAC config","typeGuard":null,"tryCatchPattern":"if err := checkRegexPattern(pattern); err != nil {\n\treturn fmt.Errorf(\"legacy regex pattern %q rejected: %w\", pattern, err)\n}","preventionTips":["Rewrite legacy '^...$' patterns as mux variables ({id}) when upgrading GoFr.","Scan existing configs for '^'/'$' before enabling RBAC.","Document mux pattern syntax as the only supported route syntax.","Add unit tests covering each configured pattern through validate()."],"tags":["rbac","config","routing","migration","gofr"],"backgroundTag":"unsupported-route-pattern","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}