javascript - ExpressJS - Regex for matching a path doesn't work -


i have simple regex should match words made of letters (0-5) doesn't seems working. how should regex , used in expressjs? url trying validate may something.com/abcd

var express = require("express"),     app = express();  app.get("/:id(^[a-z]{0,5}$)", function(req, res) {     res.send("the right path!"); });  app.listen(8000); 

to set url accepts / followed 5 ascii characters, this:

var express = require("express"), app = express();  app.get("/[a-z]{0,5}$", function(req, res){     res.send("right path!"); }); app.listen(8000); 

result:

get http://localhost:8000/ right path!  http://localhost:8000/abcde right path!  http://localhost:8000/abcdef cannot /abcdef 

note: express case insensitive routing default. change it, put @ top of script:

app.set('case sensitive routing', true); 

now, [a-z] match lower case characters: get /abc not get /abc


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -