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

Regular expression: n in x{n}, x{n,}, x{n,m} can be any integer in quantifier expression #33486

Closed
jasonren0403 opened this issue May 8, 2024 · 2 comments · Fixed by #33525
Closed
Labels
Content:JS JavaScript docs

Comments

@jasonren0403
Copy link
Contributor

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions/Quantifiers

What specific section or headline is this issue about?

Types

What information was incorrect, unhelpful, or incomplete?

The document says n in x{n}, x{n,}, and x{n,m} is a positive integer, but in fact the regexp compiles when n===0, and even when n<0(seems "invalid" because no one ever use like that).

/a{-1}/.test('b') // false
/a{-1,}/.test('b') // false

What did you expect to see?

The correct n range in x{n}, x{n,}, and x{n,m} is mentioned. The possible 'invalid' usage n<0 may be warned.

Do you have any supporting links, references, or citations?

Microsoft docs hints that n could be any integer in {n}, {n,}, and {n,m}.

Do you have anything more you want to share?

No response

MDN metadata

Page report details
@jasonren0403 jasonren0403 added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label May 8, 2024
@github-actions github-actions bot added the Content:JS JavaScript docs label May 8, 2024
@Josh-Cena
Copy link
Member

/a{-1}/ is not a valid regular expression. It's allowed because regexes without u or v use a much laxer grammar for parsing. Please try again:

/a{-1,}/u // Uncaught SyntaxError: Invalid regular expression: /a{-1,}/u: Incomplete quantifier

What /a{-1}/ actually means is /a\{-1\}/.

@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale May 9, 2024
@Josh-Cena Josh-Cena added closed: question A user misinterpretation or support question. No action required. and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels May 9, 2024
@Josh-Cena
Copy link
Member

Actually "positive" is wrong. It should say "non-negative".

@Josh-Cena Josh-Cena reopened this May 9, 2024
@Josh-Cena Josh-Cena removed the closed: question A user misinterpretation or support question. No action required. label May 9, 2024
@github-actions github-actions bot added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label May 9, 2024
@Josh-Cena Josh-Cena removed the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:JS JavaScript docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants