Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. URLPattern
  4. hasRegExpGroups

URLPattern: hasRegExpGroups property

Baseline 2025
Newly 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:

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.

js
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.

js
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.

js
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

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp