0

I looked at the following posts but they did not help with this. It's probably simple, alas...

Express routes parameter conditions

https://forbeslindesay.github.io/express-route-tester/

I have the following regex - /^\d+x\d+/i. I want a number separated by an x, so a route would be /100x100,

The regex works on it's own, but not as a route. I tried various escapeings but I keep getting a 404 back. What would be the correct syntax? (I tried something like this already router.get('/\/^\d+x\d+/i'))

PS - As my plan is only to accept digit x digit, I'd be happy to hear about any flaws in this regex.

Mote Zart
  • 861
  • 3
  • 17
  • 33

1 Answers1

1

That's an interesting problem. This is one solution to achieve what you are looking for.

router.get('^/:dimensions([0-9]+[x][0-9]+)', function(req, res) {
  //to show you that it hits the route and what it catches
  res.send('Route match for dimensions: ' + req.params.dimensions);
});
Aaron
  • 1,226
  • 9
  • 10
  • Yeah, this works! Why is it not possible to use the regex I supplied? Is it a syntax thing? Or is it just wrong? (if so why?- trying to improve my regex :) – Mote Zart Sep 20 '18 at 18:18