This feature is not Baseline because it does not work in some of the most widely-used browsers.
Note: This feature is available in Web Workers.
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.
You can use the hasRegExpGroups property to check if a URLPattern object is usable with certain web platform APIs which do not allow regular expression capturing groups. For example:
match directive in the Use-As-Dictionary HTTP header prohibits regular expression capturing groups, as well asurlPattern condition when adding static routes using the InstallEvent.addRoutes() method.A boolean.
hasRegExpGroups
In the following example, a URLPattern object is used with a group delimiter containing named capturing groups called "id" and "title". The hasRegExpGroups property returns true in this case.
const pattern = new URLPattern({ pathname: "/blog/:id(\\d+){-:title}?" });
console.log(pattern.hasRegExpGroups); // true
const result = pattern.exec({ pathname: "/blog/123-some-article" });
console.log(result.pathname.groups); // {id: '123', title: 'some-article'}
It also works with anonymous capturing groups.
const pattern = new URLPattern({ pathname: "/blog/(\\d+)" });
console.log(pattern.hasRegExpGroups); // true
const result = pattern.exec({ pathname: "/blog/123" });
console.log(result.pathname.groups); // {0: '123'}
For other non-capturing groups, for example when using wildcard tokes (*), hasRegExpGroups will return false.
const pattern = new URLPattern({ pathname: "/blog/*" });
console.log(pattern.hasRegExpGroups); // false
const result = pattern.exec({ pathname: "/blog/123" });
console.log(result.pathname.groups); // {0: '123'}
| Specification |
|---|
| URL Pattern> # dom-urlpattern-hasregexpgroups> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
hasRegExpGroups |
122 | 122 | 142 | 108 | 26 | 122 | 142 | 81 | 26 | 26.0 | 122 | 26 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/URLPattern/hasRegExpGroups