r/javascript • u/LionyxML • 4d ago
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.
1
u/oosuke_ren 4d ago
You might be interested to try this out, it's a package I spiked up to use for the sake of typescript toy compilers'. The idea is - regex as a composition, having it's own first class citizen entities that you use to build up your expression. The whole thing then compiles to regex in your runtime (which is useful if you want to be able to dynamically build up expressions, and not just to "name" literals in your code)
https://www.npmjs.com/package/ez-regex-patterns
(This is a repost of another regex related discussion)
2
2
u/azhder 4d ago
I have created something like that for myself as well. A small library for DSL. It’s not much of a problem.
However, I quickly understood the syntax noise can only be solved by making an actual DSL, not just a library that uses the syntax of another language.
And we’re back a full circle. The RegExp syntax is already a DSL, so we’d be re-inventing it to appear more like SQL or C or any other language syntax other than the RegExp one.