简体   繁体   中英

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.render('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

不要角色,但是:

/^\/blog_update\/.*/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM