URLPattern: hasRegExpGroups property
Baseline 2025Newly available
Since September 2025, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Note: This feature is available inWeb Workers.
ThehasRegExpGroups read-only property of theURLPattern interface is a boolean indicating whether or not any of theURLPattern components containregular expression capturing groups.
You can use thehasRegExpGroups property to check if aURLPattern object is usable with certain web platform APIs which do not allow regular expression capturing groups. For example:
- The
matchdirective in theUse-As-DictionaryHTTP header prohibits regular expression capturing groups, as well as - the
urlPatterncondition when adding static routes using theInstallEvent.addRoutes()method.
In this article
Value
A boolean.
Examples
>UsinghasRegExpGroups
In the following example, aURLPattern object is used with a group delimiter containing named capturing groups called "id" and "title". ThehasRegExpGroups property returnstrue in this case.
const pattern = new URLPattern({ pathname: "/blog/:id(\\d+){-:title}?" });console.log(pattern.hasRegExpGroups); // trueconst 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); // trueconst 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 returnfalse.
const pattern = new URLPattern({ pathname: "/blog/*" });console.log(pattern.hasRegExpGroups); // falseconst result = pattern.exec({ pathname: "/blog/123" });console.log(result.pathname.groups); // {0: '123'}Specifications
| Specification |
|---|
| URL Pattern> # dom-urlpattern-hasregexpgroups> |