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

Conversation

tunetheweb
Copy link
Contributor

@tunetheweb tunetheweb commented Aug 23, 2024

Description

A URLPattern uses parentheses to define Regexs as shown in one fo the examples currently on MDN:

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

Here the (\\d+) is a regex as it's surrounded by parentheses. However it's not obvious that parentheses are what allow you to use regular expressions since they are so common (especially in regexes themselves when they defined groups) so this is easily missed. So I'm suggesting wording to make this more explicit.

Motivation

I didn't understand this and wasted a lot of time on it. I'm hoping to avoid others doing the same.

Additional details

I also raised an issue for the spec to see if they want to make it clearer too:
whatwg/urlpattern#229

Related issues and pull requests

@tunetheweb tunetheweb requested a review from a team as a code owner August 23, 2024 17:15
@tunetheweb tunetheweb requested review from sideshowbarker and removed request for a team August 23, 2024 17:15
@github-actions github-actions bot added the Content:WebAPI Web API docs label Aug 23, 2024
@github-actions github-actions bot added the size/s [PR only] 6-50 LoC changed label Aug 23, 2024
Copy link
Contributor

github-actions bot commented Aug 23, 2024

Preview URLs

(comment last updated: 2024-08-23 17:31:56)

@sideshowbarker sideshowbarker merged commit f9a203c into mdn:main Aug 23, 2024
8 checks passed
@tunetheweb tunetheweb deleted the url-pattern-regexes branch August 23, 2024 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:WebAPI Web API docs size/s [PR only] 6-50 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants