Skip to content

fix regex \d, \w, \s character classes#490

Merged
cs01 merged 1 commit intomainfrom
fix-regex-character-classes
Mar 20, 2026
Merged

fix regex \d, \w, \s character classes#490
cs01 merged 1 commit intomainfrom
fix-regex-character-classes

Conversation

@cs01
Copy link
Owner

@cs01 cs01 commented Mar 20, 2026

Summary

  • \d, \w, \s (and their negated forms \D, \W, \S) were silently matching literal characters instead of their character classes — e.g., /\d+/ matched the letter "d" instead of digits
  • Root cause: ChadScript uses POSIX regcomp/regexec which doesn't support Perl-style shorthand classes. \d in POSIX means literal "d"
  • Fix: translate JS regex shorthands to POSIX equivalents before compilation (\d[0-9], \w[a-zA-Z0-9_], \s[ \t\n\r], etc.)
  • Handles shorthands both inside and outside bracket expressions

Test plan

  • New test fixture regex-character-classes.ts covering all 6 shorthands, negated forms, quantifiers, and test() method
  • All 769 tests pass
  • Self-hosting verification passes

🤖 Generated with Claude Code

@github-actions
Copy link
Contributor

Benchmark Results (Linux x86-64)

Benchmark C ChadScript Go Node Bun Place
Binary Trees 1.673s 1.271s 2.690s 1.290s 1.068s 🥈
Cold Start 0.8ms 0.9ms 1.2ms 25.6ms 9.7ms 🥈
Fibonacci 0.909s 1.410s 1.733s 3.397s 2.062s 🥈
File I/O 0.089s 0.094s 0.087s 0.176s 0.185s 🥉
JSON Parse/Stringify 0.004s 0.005s 0.016s 0.015s 0.007s 🥈
Matrix Multiply 0.489s 0.741s 0.788s 0.426s 0.399s #4
Monte Carlo Pi 0.440s 0.440s 0.458s 2.607s 6.493s 🥇
N-Body Simulation 1.750s 2.253s 2.289s 2.415s 3.327s 🥈
Quicksort 0.246s 0.283s 0.242s 0.292s 0.261s #4
SQLite 0.322s 0.365s 0.418s 0.391s 🥈
Sieve of Eratosthenes 0.015s 0.027s 0.020s 0.042s 0.036s 🥉
String Manipulation 0.008s 0.044s 0.016s 0.040s 0.030s #5

CLI Tool Benchmarks

Benchmark ChadScript grep node xxd Place
Hex Dump 0.431s 1.007s 0.138s 🥈
Recursive Grep 0.022s 0.012s 0.100s 🥈

@cs01 cs01 merged commit f31566d into main Mar 20, 2026
13 checks passed
@cs01 cs01 deleted the fix-regex-character-classes branch March 20, 2026 20:02
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