urlPattern.exec(input[, baseURL])
-
baseURL
<string> | <undefined> 基本 URL 字符串¥
baseURL
<string> | <undefined> A base URL string
输入可以是字符串或提供各个 URL 部分的对象。对象成员可以是 protocol
、username
、password
、hostname
、port
、pathname
、search
、hash
或 baseURL
中的任意一个。
¥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": "" }
// }