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
URLPattern
object based on the given pattern and base URL.
Instance properties
hash
Read onlyA string containing a pattern to match thehash partof a URL.
hasRegExpGroups
Read onlyA boolean indicating whether or not any of the
URLPattern
components containregular expression capturing groups.hostname
Read onlyA string containing a pattern to match thehostnamepart of a URL.
password
Read onlyA string containing a pattern to match thepasswordpart of a URL.
pathname
Read onlyA string containing a pattern to match thepathnamepart of a URL.
port
Read onlyA string containing a pattern to match theport partof a URL.
protocol
Read onlyA string containing a pattern to match theprotocolpart of a URL.
search
Read onlyA string containing a pattern to match thesearch partof a URL.
username
Read onlyA string containing a pattern to match theusernamepart of a URL.
Instance methods
Specifications
Specification |
---|
URL Pattern> # urlpattern> |
Browser compatibility
Loading…
See also
- A polyfill of
URLPattern
is availableon GitHub - The pattern syntax used by URLPattern is similar to the syntax used bypath-to-regexp