Skip to content

Conversation

@kevinsimper
Copy link
Contributor

A few examples of how to best approach the regex routing :)

app.get('/post/:date{[0-9]+}/:title{[a-z]+}', async (c) => {
const { date, title } = c.req.param()
// ^?
// e.g. /post/2025/my-post -> date = "2025", title = "my-post" (if [a-z-]+)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the explanation of "my-post" with [a-z-]+ is not necessary. It's just about regexp syntax. So only the following is needed:

e.g. /post/2025/mypost -> date = "2025", title = "mypost"

//
// This means paths like /file/dog.png will match, making filename "data.png".
// Paths like /file/.png (empty name part) or /file/data.png.txt (wrong suffix) will not match.
app.get('/post/:filename{.+\\.png$}', async (c) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be clear that filename can contain /. For example, make the app as follows:

app.get('/file/:filename{.+\\.png$}', async (c) => {
  const { filename } = c.req.param()
  // ...
})

And explain that accessing /file/foo/bar.png will make filename be foo/bar.png. How about it?

codeOwlAI pushed a commit to codeOwlAI/website that referenced this pull request Jun 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants