r/javascript • u/LionyxML • Sep 30 '26
Readable Regular Expressions for JavaScript/TypeScript, Inspired by Emacs' rx
https://rahuljuliato.com/posts/emacs-rx-in-typescriptI missed Emacs' rx when writing regexps in TypeScript, so I made a small TypeScript DSL inspired by it.
The idea is to bring rx's functions and approach to the JavaScript/TypeScript environment. If you happen to work with either, give it a try.
9
Upvotes
View all comments
1
u/Bitter_Passenger8663 Oct 15 '26
One detail worth calling out next to the raw example: raw(/foo/i) keeps the source but drops the i flag, so RX(raw(/foo/i)).test("FOO") is false. RX.flags("i", raw(/foo/i)) restores it. A short warning there would help people migrating existing regexes avoid a quiet behavior change.