Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Apply regular expression for expressjs

Apply regular expression for expressjs


I need to handle requests like this:


I wrote regexp that work in RegexPal


I create handler in Express.js


but it returns only last part of the key

req.params.key == '53538'

how can I retrieve full key?

Problem courtesy of: farlenkov


The problem seems to be that you accidently capture the digits, and only the last capture is returned. Try either:






The only difference is that it allows leading and consecutive periods. If you know that will never be the case, or not a problem, then this regex is a lot easier to read.

Solution courtesy of: Martin Ender


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Apply regular expression for expressjs


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription