Since I am learning Javascript and Express.js at the same time I was experimenting around with regular expressions when making a get request
To familiaries my self with regular expressions I used this chart (also reproduced below)
Greedy Reluctant Possessive Meaning
X? X?? X?+ X, once or not at all
X* X*? X*+ X, zero or more times
X+ X+? X++ X, one or more times
X{n} X{n}? X{n}+ X, exactly n times
X{n,} X{n,}? X{n,}+ X, at least n times
X{n,m} X{n,m}? X{n,m}+ X, at least n but not more than m times
My question is that how can I get a regex to match a url if it only has one /
.
In other words, it would only match the default url localhost:1337/
app.get(//{1}/, function (req, res) {
res.render("index");
});
However, my current regex above matches other pathnames(ie. localhost:1337/home/login
) because now I know it uses the greedy quantifier
After reading more on regular expressions, I changed the quantifier so its possessive.
//{1}+/
But then express gave this error:
Syntax Error: Invalid Regular Expression: //{1}+/: Nothing to Repeat
So is my syntax for the regular expression wrong?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…