[英]What's the difference between `/:foo*` and `/:foo(.*)` in express routes?
In express, we can define some endpoints with some paths: 在express中,我们可以使用一些路径定义一些端点:
app.get('/:foo*', function(req, res) { ... });
app.get('/:foo(.*)', function(req, res) { ... });
The two paths are quite similar, what's the difference between them? 两条路径非常相似,它们之间有什么区别?
*
matches zero or more of the preceding tokens *
匹配前面标记中的零个或多个
Given the string /:foo/apple/banana/:foo/:1234
给定字符串
/:foo/apple/banana/:foo/:1234
/:foo* matches: /:foo/apple/banana/:foo/:1234
^^^^^ ^^^^^
(.*)
is a capturing group which will match all 0 or more of the preceding characters. (.*)
是一个捕获组,它将匹配前面所有0个或多个字符。 The character in question is a wild card which means when we see /:foo
we will continue to match until we reach the end of the string 有问题的角色是外卡,这意味着当我们看到
/:foo
我们会继续匹配,直到我们到达字符串的末尾
Given the string /hello/world/:foo/bar?id=123
给定字符串
/hello/world/:foo/bar?id=123
/:foo(.*) matches /hello/world/:foo/bar?id=123
^^^^^^^^^^^^^^^^
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.