URLPattern

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

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() Experimental

Returns a new URLPattern object based on the given pattern and base URL.

Instance properties

hash Read only Experimental

A string containing a pattern to match the hash part of a URL.

hostname Read only Experimental

A string containing a pattern to match the hostname part of a URL.

password Read only Experimental

A string containing a pattern to match the password part of a URL.

pathname Read only Experimental

A string containing a pattern to match the pathname part of a URL.

port Read only Experimental

A string containing a pattern to match the port part of a URL.

protocol Read only Experimental

A string containing a pattern to match the protocol part of a URL.

A string containing a pattern to match the search part of a URL.

username Read only Experimental

A string containing a pattern to match the username part of a URL.

Instance methods

exec() Experimental

Returns an object with the matched parts of the URL or null if the URL does not match.

test() Experimental

Returns true if the URL matches the given pattern, false otherwise.

Specifications

Specification
URL Pattern
# urlpattern

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
URLPattern
Experimental
URLPattern() constructor
Experimental
ignoreCase option
Experimental
exec
Experimental
hasRegExpGroups
Experimental
hash
Experimental
hostname
Experimental
password
Experimental
pathname
Experimental
port
Experimental
protocol
Experimental
search
Experimental
test
Experimental
username
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

See also

  • A polyfill of URLPattern is available on GitHub
  • The pattern syntax used by URLPattern is similar to the syntax used by path-to-regexp