fix(regex): Correct \q{} disjunction-order example in Character_class#44557
fix(regex): Correct \q{} disjunction-order example in Character_class#44557Ashish-CodeJourney wants to merge 1 commit into
Conversation
|
Preview URLs (1 page) |
|
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. |
|
@Josh-Cena any updates ? |
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/\nescapes, 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\nmust be listed before\rto ever match as a pair. The article also never explained thatv-mode character classes try to match the longest operand first, which is the actual reason\q{\r\n}can sit after\rand\nin the class and still match correctly.Additional details
See the
Atom :: CharacterClasscase of theCompileAtomsyntax-directed operation in the regex spec for how a character class tries to match longer strings first.Related issues and pull requests
Fixes #44526