gofr-dev/gofr · error
regex pattern '^...$' is not supported, use mux patterns ins
Error message
regex pattern '^...$' is not supported, use mux patterns instead
What it means
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.
Source
Thrown at pkg/gofr/rbac/config.go:31
"go.opentelemetry.io/otel/trace"
"gopkg.in/yaml.v3"
"gofr.dev/pkg/gofr/container"
"gofr.dev/pkg/gofr/datasource"
)
var (
// errUnsupportedFormat is returned when the config file format is not supported.
errUnsupportedFormat = errors.New("unsupported config file format")
// ErrEndpointMissingPermissions is returned when an endpoint doesn't specify requiredPermissions and is not public.
ErrEndpointMissingPermissions = errors.New("endpoint must specify requiredPermissions (or be public)")
// errWildcardPatternNotSupported is returned when a wildcard pattern is used.
errWildcardPatternNotSupported = errors.New("wildcard pattern '/*' is not supported, use mux patterns instead")
// errRegexPatternNotSupported is returned when an old regex pattern is used.
errRegexPatternNotSupported = errors.New("regex pattern '^...$' is not supported, use mux patterns instead")
// errRegexIndicatorNotSupported is returned when regex indicators are used outside variable constraints.
errRegexIndicatorNotSupported = errors.New("regex pattern is not supported, use mux patterns instead")
)
// RoleDefinition defines a role with its permissions and inheritance.
// Pure config-based: only role->permission mapping is supported.
type RoleDefinition struct {
// Name is the role name (required)
Name string `json:"name" yaml:"name"`
// Permissions is a list of permissions for this role (format: "resource:action")
// Example: ["users:read", "users:write"]
Permissions []string `json:"permissions,omitempty" yaml:"permissions,omitempty"`
// InheritsFrom lists roles this role inherits permissions from
// Example: ["viewer"] - editor inherits all viewer permissions
InheritsFrom []string `json:"inheritsFrom,omitempty" yaml:"inheritsFrom,omitempty"`View on GitHub (pinned to 187eb24962)
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.
Example fix
// before
"^/users/[0-9]+$": {"GET": ["admin"]}
// after
"/users/{id}": {"GET": ["admin"]} Defensive patterns
Strategy: validation
Validate before calling
func isAnchoredRegex(pattern string) bool {
return strings.HasPrefix(pattern, "^") || strings.HasSuffix(pattern, "$")
}
// reject anchored regex patterns before loading RBAC config Try / catch
if err := checkRegexPattern(pattern); err != nil {
return fmt.Errorf("legacy regex pattern %q rejected: %w", pattern, err)
} Prevention
- 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().
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- wildcard pattern '/*' is not supported, use mux patterns ins
- regex pattern is not supported, use mux patterns instead
- unsupported config file format
- endpoint must specify requiredPermissions (or be public)
- failed to read RBAC config file %s: %w
AI-assisted analysis of gofr-dev/gofr@187eb24962 (2026-09-01).
Data as JSON: /api/errors/a1ad898cc394b184.
Report an issue: GitHub.