简体   繁体   English

快递路线中`/:foo *`和`/:foo(。*)`有什么区别?

[英]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.

相关问题 foo(),foo和function(){foo()}之间的js区别 - js difference between foo(), foo and function(){foo()} foo()和function()之间的区别{foo(); } - Difference between foo() and function() { foo(); } JavaScript中a =='foo'和'foo'== a之间的区别 - Difference between a == 'foo' and 'foo' == a in javascript 'function foo(callback)'和'foo(arg1,arg2,function(err,data))'之间有什么区别? - What's the difference between 'function foo (callback)' and 'foo(arg1, arg2, function(err,data))'? `when(foo,f)`和`when(foo).then(f)`有什么区别 - What is the difference between `when(foo, f)` and `when(foo).then(f)` Javascript 中的 function foo(){} 和 foo: function(){} 有什么区别? - What is the difference between function foo(){} and foo: function(){} in Javascript? let foo = ({bar() {}}) 和 let foo = {bar() {}} 有什么区别? - What is the difference between let foo = ({bar() {}}) and let foo = {bar() {}}? 新的Foo和新的Foo()在javascript中有什么区别? - What is the difference between new Foo and new Foo() in javascript? Boolean(foo.bar)和!! foo.bar有什么区别? - What is the difference between Boolean(foo.bar) and !!foo.bar? Throw'foo',throw Error('foo'),throw new Error('foo')和有什么区别? - What is the difference between `throw 'foo'`, `throw Error('foo')`, `throw new Error('foo')`?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM