A couple months ago I launched a new open source project, Oniguruma-To-ES. You can use it to:
- Take advantage of Oniguruma's many extended regex features in JavaScript.
- Run regexes written for Oniguruma from JavaScript, such as those used in TextMate grammars (used by VS Code, Shiki syntax highlighter, etc.).
- Share regexes across your Ruby and JavaScript code.✳︎
Oniguruma-To-ES deeply understands the hundreds of large and small differences between Oniguruma and JavaScript regex syntax and behavior, across multiple JavaScript version targets. It's obsessive about ensuring that the emulated features it supports have exactly the same behavior, even in extreme edge cases. And it's been battle-tested on thousands of real-world Oniguruma regexes used in TextMate grammars (via the Shiki library).
Depending on features used, Oniguruma-To-ES might use advanced emulation via a RegExp
subclass (that remains a native JavaScript regular expression).
There's also a demo page. Check it out!
✳︎: Ruby 2.0+ uses Onigmo, a fork of Oniguruma with similar syntax and behavior.