0
votes

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

The url is :

http://DOMAIN:PORT/reverseproxy/map.google.com/maps?q=lat,lon

The regex i'm using is :

\/reverseproxy\/([^/]*)(.*)

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.

1
The URL is your question does not match the one in regex101. - sp00m
thx, edited the question with the url from regex101 - Quadear

1 Answers

0
votes

Try this regex:

\/reverseproxy\/(.+[^\/]*)(\/.+)$