Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make meaning of parentheses for regex explicit in URL Pattern API #35571

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions files/en-us/web/api/url_pattern_api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ can contain:
- Non-capturing groups (`/books{/old}?`) which make parts of a pattern optional
or be matched multiple times.
- {{jsxref("RegExp")}} groups (`/books/(\\d+)`) which make arbitrarily complex
regex matches with a few [limitations](#regex_matchers_limitations).
regex matches with a few [limitations](#regex_matchers_limitations). _Note that the
parentheses are not part of the regex but instead define their contents as a regex._

You can find details about the syntax in the [pattern syntax](#pattern_syntax)
section below.
Expand Down Expand Up @@ -79,9 +80,9 @@ match the shortest possible string.
### Regex matchers

Instead of using the default match rules for a group, you can use a regex for
each group. This regex defines the matching rules for the group. Below is an
example of a regex matcher on a named group that constrains the group to only
match if it contains one or more digits:
each group by including a regex in parentheses. This regex defines the matching
rules for the group. Below is an example of a regex matcher on a named group
that constrains the group to only match if it contains one or more digits:

```js
const pattern = new URLPattern("/books/:id(\\d+)", "https://example.com");
Expand Down