MDN Web Docs

Constructor

URLPattern()

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

Instance properties

hash Read only

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

hasRegExpGroups Read only

A boolean indicating whether or not any of the URLPattern components contain regular expression capturing groups.

hostname Read only

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

password Read only

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

pathname Read only

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

port Read only

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

protocol Read only

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

search Read only

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

username Read only

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

Instance methods

exec()

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

test()

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

Specifications

Specification
URL Pattern
# urlpattern

Browser compatibility

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

Help improve MDN

Yes No

Learn how to contribute

This page was last modified on by MDN contributors.

Read the original on developer.mozilla.org ↗