Why this router works
app.get(/regularExpression/, function (req, res, next) {
});
But this don't work Cannot GET
var regularExpressionString = "regularExpressionString";
var regularExpression = new RegExp(regularExpressionString);
app.get(regullarExpression, function (req, res, next) {
});
I need the second variant because I want to reuse router string parts according to DRY principle without repeating code. But when I use /regularExpression/
I cannot concat strings like /regularExpressionString1 + regularExpressionString2/
.
So how to concat strings in node.js express regex route?
update
new RegExp
works if I don't use special symbols like \d
or \w
For example this pattern works:
regex = new RegExp('/(32)teeth')
But this don't:
regex = new RegExp('/(\d+)teeth')