URLPattern
Baseline
2025
Newly 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 in Web Workers.
The URLPattern interface of the URL 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 overview page: URL Pattern API.
Constructor
URLPattern()-
Returns a new
URLPatternobject based on the given pattern and base URL.
Instance properties
hashRead only-
A string containing a pattern to match the hash part of a URL.
hasRegExpGroupsRead only-
A boolean indicating whether or not any of the
URLPatterncomponents contain regular expression capturing groups. hostnameRead only-
A string containing a pattern to match the hostname part of a URL.
passwordRead only-
A string containing a pattern to match the password part of a URL.
pathnameRead only-
A string containing a pattern to match the pathname part of a URL.
portRead only-
A string containing a pattern to match the port part of a URL.
protocolRead only-
A string containing a pattern to match the protocol part of a URL.
searchRead only-
A string containing a pattern to match the search part of a URL.
usernameRead only-
A string containing a pattern to match the username part of a URL.
Instance methods
Specifications
| Specification |
|---|
| URL Pattern # urlpattern |
Browser compatibility
| desktop | mobile | server | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
URLPattern
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
URLPattern() constructor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ignoreCase option
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
exec
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hasRegExpGroups
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hash
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
hostname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
password
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pathname
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
port
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protocol
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
search
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
username
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
See also
- A polyfill of
URLPatternis available on GitHub - The pattern syntax used by URLPattern is similar to the syntax used by path-to-regexp