Skip to content

fix(regex): Correct \q{} disjunction-order example in Character_class#44557

Open
Ashish-CodeJourney wants to merge 1 commit into
mdn:mainfrom
Ashish-CodeJourney:44526
Open

fix(regex): Correct \q{} disjunction-order example in Character_class#44557
Ashish-CodeJourney wants to merge 1 commit into
mdn:mainfrom
Ashish-CodeJourney:44526

Conversation

@Ashish-CodeJourney

Copy link
Copy Markdown
Contributor

Description

Fixes the \q{} example in the "Matching strings" section of the Character class reference page. Replaces the confusing template-literal test string with a plain string literal and a correct sample output, fixes the incorrect equivalence claim about disjunction order, and adds an explanation of why \q{\r\n} can appear at the end of the character class.

Motivation

The original example used a template literal mixing real line breaks with \r/\n escapes, so the commented return value didn't match what the regex actually produces. The explanation that followed was also wrong: it claimed the regex was equivalent to forms like \r|\r\n, but disjunction in a regex is not commutative an engine tries alternatives left to right and stops at the first match, so \r\n must be listed before \r to ever match as a pair. The article also never explained that v-mode character classes try to match the longest operand first, which is the actual reason \q{\r\n} can sit after \r and \n in the class and still match correctly.

Additional details

See the Atom :: CharacterClass case of the CompileAtom syntax-directed operation in the regex spec for how a character class tries to match longer strings first.

Related issues and pull requests

Fixes #44526

@Ashish-CodeJourney Ashish-CodeJourney requested a review from a team as a code owner June 23, 2026 10:09
@Ashish-CodeJourney Ashish-CodeJourney requested review from wbamberg and removed request for a team June 23, 2026 10:09
@github-actions github-actions Bot added Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed labels Jun 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@DominoPivot

Copy link
Copy Markdown

Looks good to me! I wasn't sure if an explanation for this behavior should go earlier in the article, but in hindsight I think this is fine. It's a niche enough feature that teaching it by example is probably ideal.

Thanks for making the PR, I haven't contributed since MDN was converted from a wiki and still need to familiarize myself with the process. For future reference, is it typical to propose small changes by only opening a PR without an associated issue?

@Ashish-CodeJourney

Copy link
Copy Markdown
Contributor Author

Looks good to me! I wasn't sure if an explanation for this behavior should go earlier in the article, but in hindsight I think this is fine. It's a niche enough feature that teaching it by example is probably ideal.

Thanks for making the PR, I haven't contributed since MDN was converted from a wiki and still need to familiarize myself with the process. For future reference, is it typical to propose small changes by only opening a PR without an associated issue?

For small changes, it's usually fine to contribute without opening an issue first. However, opening one is still recommended so others can understand the motivation behind the proposed change.

@Ashish-CodeJourney

Copy link
Copy Markdown
Contributor Author

@Josh-Cena any updates ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs size/s [PR only] 6-50 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect example for \q{} in regular expression character class

3 participants