Skip to content

Treat [ as a literal inside a regex character class - #2204

Merged
slozier merged 1 commit into
IronLanguages:mainfrom
deronnax:fix-re-bracket-in-class
Dec 4, 2026
Merged

slozier merged 1 commit into
IronLanguages:mainfrom
deronnax:fix-re-bracket-in-class

Conversation

@deronnax

@deronnax deronnax commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

re.compile(r'[+-[]') failed with Unterminated [] set: .NET reads -[ inside a character class as the start of a class subtraction. The literal [ characters of character classes are now escaped.

Test: test_bracket_in_character_class in tests/suite/modules/io_related/test_re.py. On 61948 generated patterns compared with CPython, the number of identical results goes from 61531 on main to 61892; the remaining differences are about the ++/^+ quantifiers of recent CPython and about comments containing \).

Written with Claude Sonnet 5.5, reasoning effort: medium.

.NET reads -[ inside a character class as the start of a class subtraction,
so that patterns such as [+-[] failed to compile. Escape the literal [
characters of character classes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@slozier slozier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@slozier
slozier merged commit 624938f into IronLanguages:main Dec 4, 2026
41 checks passed
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.

2 participants