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
Post a Comment