URLPattern
URL Pattern API
URL Pattern API
The URLPattern interface of the 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: .
Constructor
- URLPattern()
- : Returns a new
URLPatternobject based on the given pattern and base URL.
Instance properties
- hash
- : A string containing a pattern to match the hash part of a URL.
- hasRegExpGroups
- : A boolean indicating whether or not any of the
URLPatterncomponents contain regular expression capturing groups. - hostname
- : A string containing a pattern to match the hostname part of a URL.
- password
- : A string containing a pattern to match the password part of a URL.
- pathname
- : A string containing a pattern to match the pathname part of a URL.
- port
- : A string containing a pattern to match the port part of a URL.
- protocol
- : A string containing a pattern to match the protocol part of a URL.
- search
- : A string containing a pattern to match the search part of a URL.
- username
- : 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
nullif the URL does not match. - test()
- : Returns
trueif the URL matches the given pattern,falseotherwise.
Specifications
Browser compatibility
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