| title | URLPattern |
|---|---|
| slug | Web/API/URLPattern |
| page-type | web-api-interface |
| browser-compat | api.URLPattern |
{{APIRef("URL Pattern API")}} {{AvailableInWorkers}}
The URLPattern interface of the {{domxref("URL Pattern API", "", "", "nocode")}} matches URLs or parts of URLs against a pattern. The pattern can contain capturing groups that extract parts of the matched URL.
More information about the syntax of patterns can be found on the API overview page: {{domxref("URL Pattern API", "", "", "nocode")}}.
- {{domxref("URLPattern.URLPattern", "URLPattern()")}}
- : Returns a new
URLPatternobject based on the given pattern and base URL.
- : Returns a new
- {{domxref("URLPattern.hash", "hash")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the hash part of a URL.
- {{domxref("URLPattern.hasRegExpGroups", "hasRegExpGroups")}} {{ReadOnlyInline}}
- : A boolean indicating whether or not any of the
URLPatterncomponents contain regular expression capturing groups.
- : A boolean indicating whether or not any of the
- {{domxref("URLPattern.hostname", "hostname")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the hostname part of a URL.
- {{domxref("URLPattern.password", "password")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the password part of a URL.
- {{domxref("URLPattern.pathname", "pathname")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the pathname part of a URL.
- {{domxref("URLPattern.port", "port")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the port part of a URL.
- {{domxref("URLPattern.protocol", "protocol")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the protocol part of a URL.
- {{domxref("URLPattern.search", "search")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the search part of a URL.
- {{domxref("URLPattern.username","username")}} {{ReadOnlyInline}}
- : A string containing a pattern to match the username part of a URL.
- {{domxref("URLPattern.exec", "exec()")}}
- : Returns an object with the matched parts of the URL or
nullif the URL does not match.
- : Returns an object with the matched parts of the URL or
- {{domxref("URLPattern.test", "test()")}}
- : Returns
trueif the URL matches the given pattern,falseotherwise.
- : Returns
{{Specifications}}
{{Compat}}
- A polyfill of
URLPatternis available on GitHub - The pattern syntax used by URLPattern is similar to the syntax used by path-to-regexp