类:URLPattern


¥Class: URLPattern

稳定性: 1 - 实验性的

¥Stability: 1 - Experimental

URLPattern API 提供了一个接口,用于将 URL 或 URL 的部分与模式进行匹配。

¥The URLPattern API provides an interface to match URLs or parts of URLs against a pattern.

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": "" }
// }

console.log(myPattern.test('https://nodejs.cn/docs/latest/api/dns.html'));
// Prints: true