URL Pattern API
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.URLPattern
- : Returns a new
URLPatternobject based on the given pattern and base URL.
- : Returns a new
Instance properties
- URLPattern.hash
- : A string containing a pattern to match the hash part of a URL.
- URLPattern.hasRegExpGroups
- : A boolean indicating whether or not any of the
URLPatterncomponents contain regular expression capturing groups.
- : A boolean indicating whether or not any of the
- URLPattern.hostname
- : A string containing a pattern to match the hostname part of a URL.
- URLPattern.password
- : A string containing a pattern to match the password part of a URL.
- URLPattern.pathname
- : A string containing a pattern to match the pathname part of a URL.
- URLPattern.port
- : A string containing a pattern to match the port part of a URL.
- URLPattern.protocol
- : A string containing a pattern to match the protocol part of a URL.
- URLPattern.search
- : A string containing a pattern to match the search part of a URL.
- URLPattern.username
- : A string containing a pattern to match the username part of a URL.
Instance methods
- URLPattern.exec
- : Returns an object with the matched parts of the URL or
nullif the URL does not match.
- : Returns an object with the matched parts of the URL or
- URLPattern.test
- : Returns
trueif the URL matches the given pattern,falseotherwise.
- : Returns
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
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
