Skip to content

Commit

Permalink
Make meaning of parentheses for regex explicit in URL Pattern API (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
tunetheweb authored Aug 23, 2024
1 parent 545804c commit f9a203c
Showing 1 changed file with 5 additions and 4 deletions.
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

0 comments on commit f9a203c

Please sign in to comment.