Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/deno/cli/dts/lib.dom.extras.d.ts>URLPattern#exec

A modern runtime for JavaScript and TypeScript.
Go to Latest
method URLPattern.prototype.exec
import { URLPattern } from "https://deno.land/x/deno@v1.28.0/cli/dts/lib.dom.extras.d.ts";

Match the given input against the stored pattern.

The input can either be provided as a url string (with an optional base), or as individual components in the form of an object.

const pattern = new URLPattern("https://example.com/books/:id");

// Match a url string.
let match = pattern.exec("https://example.com/books/123");
console.log(match.pathname.groups.id); // 123

// Match a relative url with a base.
match = pattern.exec("/books/123", "https://example.com");
console.log(match.pathname.groups.id); // 123

// Match an object of url components.
match = pattern.exec({ pathname: "/books/123" });
console.log(match.pathname.groups.id); // 123

Parameters

optional
baseURL: string