URLPattern: hasRegExpGroups プロパティ
Baseline
2025
最近利用可能
September 2025以降、この機能は最新のバージョンの端末およびブラウザーで動作します。古い端末やブラウザーでは動作しないことがあります。
メモ: この機能はウェブワーカー内で利用可能です。
hasRegExpGroups は URLPattern インターフェイスの読み取り専用プロパティで、URLPattern 要素のいずれかが 正規表現のキャプチャグループ を含むかどうかを示す論理値です。
hasRegExpGroups プロパティを使用すると、正規表現のキャプチャグループを許可しない特定のウェブプラットフォーム API で URLPattern オブジェクトが使用可能かどうかを確認できます。例えば、
matchディレクティブは、HTTP のUse-As-Dictionaryヘッダーにおいて、正規表現のキャプチャグループを禁止します。urlPattern条件は、InstallEvent.addRoutes()メソッドを使用して静的ルートを追加する際に適用されます。
値
論理値です。
例
>hasRegExpGroups の使用
次の例では、URLPattern オブジェクトが、名前付きキャプチャグループ "id" と "title" を含むグループ区切り文字と共に使用されています。この場合、hasRegExpGroups プロパティは true を返します。
js
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'}
同様に、無名キャプチャグループでも動作します。
js
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'}
その他の非キャプチャグループの場合、例えばワイルドカードトークン (*) を使用する場合、hasRegExpGroups は false を返します。
js
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'}
仕様書
| 仕様書 |
|---|
| URL Pattern> # dom-urlpattern-hasregexpgroups> |