Skip to content

Wildcard in route parameter regexp #2495

Closed

Description

@bevacqua

Route '/:username([a-z][a-z-]*)'
Route '/:username([a-z][a-z-]*)/:project([a-z][a-z0-9-]*)'

URL /someone/project

Expectation is that the second route should match.
Actual result is the first route matches because the * is considered as all the things rather than "zero or more" [a-z-].

Activity

  1. dougwilson commented on Jan 12, 2015

    @dougwilson
    Contributor

    It's a limitation of the current version of path-to-regexp we use. A work-around would be to use the following route: /:username([a-z][a-z-]{0,}) (i.e. use {0,} in place of *).

  2. self-assigned this
    on Jan 12, 2015
  3. dougwilson commented on Jan 12, 2015

    @dougwilson
    Contributor

    I'm going to check if the most recent (non-backwards-compatible) version of path-to-regexp handles this better.

  4. dougwilson commented on Jan 12, 2015

    @dougwilson
    Contributor

    It does. So this should be fixed in 5.0, but as for 4.x, you'll probably have to just use the old syntax :/

  5. bevacqua commented on Jan 12, 2015

    @bevacqua
    Author
  6. dougwilson commented on Jan 12, 2015

    @dougwilson
  7. charlierudolph commented on May 7, 2015

    @charlierudolph

    So is path-to-regexp not going to be updated until version 5.0? That's something I would really like to see as soon as possible. Also the website is misleading because it points to path-to-regexp and its regexp tester but it is currently very out of date.

  8. dougwilson commented on May 7, 2015

    @dougwilson
    Contributor

    It's not that we don't want to upgrade path-to-regexp before 5.0, but all versions above where we are at have breaking changes and thus must wait until 5.0. We cannot upgrade path-to-regexp is a 4.x minor release if people's existing 4.x routes break.

    As for website issues, please file them at https://github.com/strongloop/expressjs.com

  9. bevacqua commented on May 7, 2015

    @bevacqua
    Author

    For what it's worth, I've been using {0,} without any inconvenients for a long while now.

  10. charlierudolph commented on May 7, 2015

    @charlierudolph
  11. bevacqua commented on May 7, 2015

    @bevacqua
    Author
  12. 12 remaining items

  13. dougwilson commented on Feb 1, 2017

    @dougwilson
    Contributor

    Using {0,} should work the same with 5.x comes out while (*) will likely change meaning in 5, I believe.

  14. ttencate commented on May 15, 2017

    @ttencate
  15. dougwilson commented on May 15, 2017

    @dougwilson
  16. ttencate commented on May 15, 2017

    @ttencate
  17. rjmunro commented on Nov 22, 2017

    @rjmunro
  18. VAggrippino commented on Mar 23, 2018

    @VAggrippino
  19. rjmunro commented on Mar 26, 2018

    @rjmunro
  20. VAggrippino commented on Mar 26, 2018

    @VAggrippino
  21. rjmunro commented on Mar 28, 2018

    @rjmunro
  22. mregydev commented on Nov 8, 2018

    @mregydev

    This issue still exist in express 5.x in spite not being exist in Path-to-RegExp

    app.get('/:number(\\d*\\d*)', (request, response) => { response.send(request.params.number) })

    It donot work with one digit parameter (http://localhost/2) but works with more than one digit parameters (http://localhost/22)

    Thanks

  23. dougwilson commented on Feb 17, 2022

    @dougwilson
    Contributor

    This is now resolved in 5.0.0-beta.1

  24. VevoLiang commented on Feb 17, 2022

    @VevoLiang
  25. added a commit that references this issue on Dec 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions