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

Misleading "try it" example for RegExp unicode flag #36523

Closed
pewscorner opened this issue Oct 27, 2024 · 1 comment
Closed

Misleading "try it" example for RegExp unicode flag #36523

pewscorner opened this issue Oct 27, 2024 · 1 comment
Labels
closed: duplicate This issue or pull request already exists Content:JS JavaScript docs

Comments

@pewscorner
Copy link

pewscorner commented Oct 27, 2024

MDN URL

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode

What specific section or headline is this issue about?

The "try it" example.

What information was incorrect, unhelpful, or incomplete?

The example uses new RegExp('\u{61}', 'u') with and without the 'u' flag to demonstrate the difference. But '\u{61}' immediately gets converted to 'a' (and becomes the value of the RegExp source property) as part of normal string literal interpretation before the string is passed to RegExp, so the 'u' flag has no effect.

What did you expect to see?

To introduce an effect, the example would need to be rewritten to use one of the following syntaxes:

  1. new RegExp('\\u{61}', 'u') (note: 2 backslashes instead of 1)
  2. /\u{61}/u

Furthermore, to make the effect of the flag clear, it is not enough to show the value of the source property. The result of a match needs to be shown, e.g.:

console.log(regex1.exec('a'));
// Expected output: null
console.log(regex1.exec('u'.repeat(61)));
// Expected output: Array ["uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu"]

console.log(regex2.exec('a'));
// Expected output: Array ["a"]
console.log(regex2.exec('u'.repeat(61)));
// Expected output: null

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

No response

Do you have anything more you want to share?

No response

MDN metadata

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

Duplicate of mdn/interactive-examples#2490

@Josh-Cena Josh-Cena marked this as a duplicate of mdn/interactive-examples#2490 Oct 27, 2024
@Josh-Cena Josh-Cena closed this as not planned Won't fix, can't repro, duplicate, stale Oct 27, 2024
@Josh-Cena Josh-Cena added closed: duplicate This issue or pull request already exists and removed needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. labels Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed: duplicate This issue or pull request already exists Content:JS JavaScript docs
Projects
None yet
Development

No branches or pull requests

2 participants