Skip to content

Regex router pattern not matching as expected. #970

Description

@mmmmmrob

This is probably me doing something wrong, as I'm new to go and chi, but any help would be really appreciated!

I am serving a URL in the form /test/f9772163-44e7-49b1-9c8c-36b8d023aa6b-2024-01-01 which is a UUID and date, separated by a -.

I hoped I could match this using a regex pattern in the router pattern string, but this fails to match.

r.Get("/test/{UUID:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}}-{date}", func(w http.ResponseWriter, r *http.Request) {
	uuidParam := chi.URLParam(r, "UUID")
	dateParam := chi.URLParam(r, "date")
	w.Write([]byte(uuidParam + "\n" + dateParam))
})

Expected:

f9772163-44e7-49b1-9c8c-36b8d023aa6b
2024-01-01

Actual:

404 page not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions