由于我同时学习 Javascript 和 Express.js,因此我在发出 get 请求时尝试使用正则表达式
为了熟悉正则表达式,我使用了这个chart http://docs.oracle.com/javase/tutorial/essential/regex/quant.html(也转载如下)
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
我的问题是,如果只有一个 url,我怎样才能得到一个正则表达式来匹配它/
.
换句话说,它只会匹配默认的urllocalhost:1337/
app.get(/\/{1}/, function (req, res) {
res.render("index");
});
但是,我当前的上面的正则表达式与其他路径名匹配(即。localhost:1337/home/login
)因为现在我知道它使用贪婪量词
在阅读了有关正则表达式的更多内容后,我更改了量词,使其成为所有格。
/\/{1}+/
但随后express给出了这个错误:
Syntax Error: Invalid Regular Expression: /\/{1}+/: Nothing to Repeat
那么我的正则表达式语法是否错误?