Skip to content

Add check for (.|\n) any-character alternations#53

Open
jvoisin wants to merge 1 commit into
thatch:masterfrom
jvoisin:alternation
Open

Add check for (.|\n) any-character alternations#53
jvoisin wants to merge 1 commit into
thatch:masterfrom
jvoisin:alternation

Conversation

@jvoisin

@jvoisin jvoisin commented Jul 15, 2026

Copy link
Copy Markdown

Flag alternations that match every character by combining . with \n (optionally with extra single-char branches like \r), e.g. (.|\n)*?. Since . already matches all but \n, this is the [\s\S] idiom spelled out as a per-character alternation, which is much slower to match than a single character class.

This is the anti-pattern cleaned up in pygments/pygments#3187.

New checker 126 (check_dot_newline_alternation), with tests.

Flag alternations that match every character by combining . with \n
(optionally with extra single-char branches like \r), e.g. (.|\n)*?.
Since . already matches all but \n, this is the [\s\S] idiom spelled
out as a per-character alternation, which is much slower to match than
a single character class.

This is the anti-pattern cleaned up in pygments/pygments#3187.

New checker 126 (check_dot_newline_alternation), with tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant