const pattern = new URLPattern("http{s}?://*.example.com/books/:id");URLPattern: exec() method / notebook
URLPattern: exec() method
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
let match = pattern.exec("https://store.example.com/books/123");
console.log(match.inputs); // ['https://store.example.com/books/123']
console.log(match.protocol); // { input: "https", groups: {} }
console.log(match.username); // { input: "", groups: {"0": ""} }
console.log(match.password); // { input: "", groups: {"0": ""} }
console.log(match.hostname); // { input: "store.example.com", groups: { "0": "store" } }
console.log(match.port); // { input: "", groups: {} }
console.log(match.pathname); // { input: "/books/123", groups: { "id": "123" } }
console.log(match.search); // { input: "", groups: {"0": ""} }
console.log(match.hash); // { input: "", groups: {"0": ""} }const pattern = new URLPattern("http{s}?://*.example.com/books/:id");match = pattern.exec("/books/123", "http://store.example.com"); // returns object
console.log(match.inputs); // ['/books/123', 'https://store.example.com']pattern.exec("/books/123", "data:text/plain,hello world!"); // returns null
pattern.exec("/books/123"); // returns nullconst pattern = new URLPattern("http{s}?://*.example.com/books/:id");pattern.exec({
protocol: "https",
hostname: "store.example.com",
pathname: "/books/123",
}); // returns objectpattern.exec({
pathname: "/books/123",
baseURL: "http://store.example.com",
}); // returns objectpattern.exec({
protocol: "file",
hostname: "store.example.com",
pathname: "/books/123",
}); // returns null