开发者

regular expression in node-express

I'm trying to understand how can I use regular expressions in express js, I want to load a page if the url has the form '/blog_update/' and then whatever string but it just wont work it gives back an error saying: Cannot GET /blog_update/my_title

app.get(/^\/blog_update\/[.*]/, function(req, res){

    res.re开发者_如何学编程nder('blog_update' , {locals:{title:'Update' }});

});


You can do it this way:

app.get('/blog_update/:id/:op?', function(req, res){
   //req.params.id
   //req.params.op
});

For the second parameter, here's a useful video for you: http://nodetuts.com/tutorials/10-express-part-ii-static-files-partials-and-locals.html#video


app.get('/qwe/((\\d+))', function(req, res){
    console.log( req.params[0] );
    res.end();
});

this route accept only numbers


Don't character class but :

/^\/blog_update\/.*/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜