URLPattern class
The URLPattern API provides a web platform primitive for matching URLs based on a convenient pattern syntax.
The syntax is based on path-to-regexp. Wildcards, named capture groups, regular groups, and group modifiers are all supported.
// Specify the pattern as structured data.
const pattern = new URLPattern({ pathname: "/users/:user" });
const match = pattern.exec("https://blog.example.com/users/joe");
console.log(match.pathname.groups.user); // joe
// Specify a fully qualified string pattern.
const pattern = new URLPattern("https://example.com/books/:id");
console.log(pattern.test("https://example.com/books/123")); // true
console.log(pattern.test("https://deno.land/books/123")); // false
// Specify a relative string pattern with a base URL.
const pattern = new URLPattern("/article/:id", "https://blog.example.com");
console.log(pattern.test("https://blog.example.com/article")); // false
console.log(pattern.test("https://blog.example.com/article/123")); // true
- Available extensions
- Annotations
-
- @JS()
- @staticInterop
Constructors
- URLPattern(Object input, [String? baseURL])
-
factory
Properties
- exec ↔ URLPatternResult? Function(Object, [String?])
-
Available on URLPattern, provided by the URLPattern$Typings extension
getter/setter pair - hash → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for thehash
.no setter - hashCode → int
-
The hash code for this object.
no setterinherited
- hostname → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for thehostname
.no setter - password → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for thepassword
.no setter - pathname → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for thepathname
.no setter - port → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for theport
.no setter - protocol → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for theprotocol
.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- search → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for thesearch
.no setter - test ↔ bool Function(Object, [String?])
-
Available on URLPattern, provided by the URLPattern$Typings extension
getter/setter pair - username → String
-
Available on URLPattern, provided by the URLPattern$Typings extension
The pattern string for theusername
.no setter
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited