go-chi / go-chi/chi

Regex router pattern not matching as expected.

Open
#970 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
22.8k
Forks
1.2k
Avg merge
5h 17m
Merged PRs (30d)
10

Description

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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.