URLPattern
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.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 95 | 95 | 142 | 26 | 95 | 26 | |
| The exec() method of the URLPattern interface takes a URL or object of URL parts, and returns either an object containing the results of matching the URL to the pattern, or null if the URL does not match the pattern. | 95 | 95 | 142 | 26 | 95 | 26 |
| The hash read-only property of the URLPattern interface is a string containing the pattern used to match the fragment part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
| The hasRegExpGroups read-only property of the URLPattern interface is a boolean indicating whether or not any of the URLPattern components contain regular expression capturing groups. | 122 | 122 | 142 | 26 | 122 | 26 |
| The hostname read-only property of the URLPattern interface is a string containing the pattern used to match the hostname part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
| The password read-only property of the URLPattern interface is a string containing the pattern used to match the password part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
| The pathname read-only property of the URLPattern interface is a string containing the pattern used to match the pathname part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
| The port read-only property of the URLPattern interface is a string containing the pattern used to match the port part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
| The protocol read-only property of the URLPattern interface is a string containing the pattern used to match the protocol part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
| The search read-only property of the URLPattern interface is a string containing the pattern used to match the search part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
| The test() method of the URLPattern interface takes a URL string or object of URL parts, and returns a boolean indicating if the given input matches the current pattern. | 95 | 95 | 142 | 26 | 95 | 26 |
| The URLPattern() constructor returns a new URLPattern object representing the URLs that will be matched by this pattern. | 95 | 95 | 142 | 26 | 95 | 26 |
URLPattern (ignoreCase option) `ignoreCase` option | 107 | 107 | 142 | 26 | 107 | 26 |
| The username read-only property of the URLPattern interface is a string containing the pattern used to match the username part of a URL. | 95 | 95 | 142 | 26 | 95 | 26 |
Use cases
-
Using URLPattern
The URLPattern interface of the URL Pattern API matches URLs or parts of URLs against a pattern.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.