URLPattern
Baseline 2025Newly available
Since September 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Note: This feature is available inWeb Workers.
TheURLPattern interface of theURL Pattern API 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 overviewpage:URL Pattern API.
In this article
Constructor
URLPattern()Returns a new
URLPatternobject based on the given pattern and base URL.
Instance properties
hashRead onlyA string containing a pattern to match thehash partof a URL.
hasRegExpGroupsRead onlyA boolean indicating whether or not any of the
URLPatterncomponents containregular expression capturing groups.hostnameRead onlyA string containing a pattern to match thehostnamepart of a URL.
passwordRead onlyA string containing a pattern to match thepasswordpart of a URL.
pathnameRead onlyA string containing a pattern to match thepathnamepart of a URL.
portRead onlyA string containing a pattern to match theport partof a URL.
protocolRead onlyA string containing a pattern to match theprotocolpart of a URL.
searchRead onlyA string containing a pattern to match thesearch partof a URL.
usernameRead onlyA string containing a pattern to match theusernamepart of a URL.
Instance methods
Specifications
| Specification |
|---|
| URL Pattern> # urlpattern> |
Browser compatibility
See also
- A polyfill of
URLPatternis availableon GitHub - The pattern syntax used by URLPattern is similar to the syntax used bypath-to-regexp