urlPattern.exec(input[, baseURL])


输入可以是字符串,也可以是提供单独 URL 部分的对象。对象成员可以是 protocolusernamepasswordhostnameportpathnamesearchhashbaseURL 中的任何一个。

【Input can be a string or an object providing the individual URL parts. The object members can be any of protocol, username, password, hostname, port, pathname, search, hash or baseURL.】

如果未指定 baseURL,它将默认为 undefined

【If baseURL is not specified, it will default to undefined.】

返回一个对象,该对象有一个 inputs 键,包含传入函数的参数数组,以及 URL 组件的键,这些键包含匹配的输入和匹配的分组。

【Returns an object with an inputs key containing the array of arguments passed into the function and keys of the URL components which contains the matched input and matched groups.】

const myPattern = new URLPattern('https://nodejs.cn/docs/latest/api/*.html');
console.log(myPattern.exec('https://nodejs.cn/docs/latest/api/dns.html'));
// Prints:
// {
//  "hash": { "groups": {  "0": "" },  "input": "" },
//  "hostname": { "groups": {}, "input": "nodejs.org" },
//  "inputs": [
//    "https://nodejs.cn/docs/latest/api/dns.html"
//  ],
//  "password": { "groups": { "0": "" }, "input": "" },
//  "pathname": { "groups": { "0": "dns" }, "input": "/docs/latest/api/dns.html" },
//  "port": { "groups": {}, "input": "" },
//  "protocol": { "groups": {}, "input": "https" },
//  "search": { "groups": { "0": "" }, "input": "" },
//  "username": { "groups": { "0": "" }, "input": "" }
// }