Quadear Quadear - 1 year ago 127
Node.js Question

Regex Path in node Express

I'm trying to make a route in Node express using regex, but it doesn't work as expected.

The url is :


The regex i'm using is :


I want to have :

$1 = map.google.com
$2 = /maps?q=lat,lon

as seen here https://regex101.com/r/wN6cZ7/117

But when i do this in express, i have not only 2 params in req.params, but 3:

0 = "aps.google"
1 = ".com/maps"
2 = "com/maps"

I don't understand why it works in the regex tester, but not in my app. Am I missing something ?

Thank you.

Answer Source

Try this regex:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download