The URL Pattern API is a web standard for matching URLs against patterns. The syntax is based on the popular path-to-regexp library used by Express, Ruby on Rails, and Next.js.
/posts/*) — match any character/books/:id) — extract parts of the matched URL/books{/old}?) — optional or repeated parts/books/(\\d+)) — complex regex matchingconst pattern = new URLPattern({ pathname: "/books/:id" });
console.log(pattern.test("https://example.com/books/123")); // true
console.log(pattern.exec("https://example.com/books/123").pathname.groups);
// { id: "123" }