fix(regex): Correct \q{} disjunction-order example in Character_class#44557
Open
Ashish-CodeJourney wants to merge 1 commit into
Open
fix(regex): Correct \q{} disjunction-order example in Character_class#44557Ashish-CodeJourney wants to merge 1 commit into
Ashish-CodeJourney wants to merge 1 commit into
Conversation
Contributor
|
Preview URLs (1 page) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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