Search code examples
node.jsregexexpressurl-routingpath-to-regexp

Express route parsing with regex characters sets


Path: /1,2,3,456,678 - only numbers and commas, not anything else
Should be matched with regex-like path like this: /ids:(\\d+[,\\d]*) natively
But https://www.npmjs.com/package/path-to-regexp in express compiles it to some ridiculous regex
Expressers/noders - pls guide me how to approach this right


Solution

  • Replacing * with {0,} solved the issue
    So request /1,2,34,56 matched by path: /ids:(\\d+[,\\d]{,*})
    Link to path-to-regexp issue: https://github.com/pillarjs/path-to-regexp/issues/233