RE2JS

Linear-time, ReDoS-safe regular expression engine for JavaScript

Library
npm
v2.8.6
204stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
78/100Good
Development Activity100
Maintenance100
Community32
Maturity52
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture85
Code Quality82
Innovation82
Learning Curve65

RE2JS is a pure JavaScript port of Google’s RE2 regular expression engine, built to guarantee linear-time O(n) matching instead of the exponential worst case that backtracking engines like the native RegExp (and PCRE/Perl/Python engines) can hit. It reaches architectural parity with Go’s regexp package by combining DFA and NFA execution strategies to explore all possible matches in a single pass over the input, which eliminates catastrophic backtracking entirely.

Because it never backtracks, RE2JS is specifically positioned as a defense against Regular Expression Denial of Service (ReDoS) attacks — a real risk any time a regex pattern or its input can come from an untrusted source (user-supplied search filters, validation rules, etc.). It ships as a dependency-free, tree-shakeable package that runs identically in Node.js and the browser, with an API modeled closely on Java’s java.util.regex naming conventions from the original RE2 implementation lineage.

What You Get

  • A drop-in-style RE2JS matcher API for compiling and executing patterns with linear-time guarantees
  • Full architectural parity with Go’s regexp package and Google’s RE2 syntax
  • Protection against catastrophic backtracking / ReDoS when matching untrusted patterns or input
  • Works identically in Node.js and browser environments with no runtime dependencies
  • Compiled build outputs for ESM, CJS, and UMD consumption

Common Use Cases

  • Validating or filtering user-supplied input where the regex pattern itself may be attacker-controlled
  • Search/filter features that accept end-user regular expressions safely
  • Replacing native RegExp in security-sensitive parsing paths (WAFs, log processors, form validators)
  • Porting Go-style regex behavior/syntax into a JavaScript codebase

Under The Hood

Architecture - The engine is organized as a classic compiler pipeline under src/: Parser.js builds an AST (Regexp.js) from pattern syntax, Compiler.js lowers it to an instruction program (Prog.js/Inst.js), and execution is handled by two interchangeable backends — Machine.js (NFA simulation) and DFA.js (deterministic automaton), with OnePass.js as a fast-path optimization and Backtracker.js retained for small patterns where backtracking is provably safe. Matcher.js and RE2.js expose the public matching API, Prefilter.js does cheap pre-filtering before full matching, and Unicode.js/UnicodeTables.js handle Unicode character class support.

Tech Stack - Pure JavaScript (ESM-first, type: module), zero runtime dependencies, built with Rolldown (rolldown.config.js) into ESM/CJS/UMD bundles with TypeScript type declarations, tested with Vitest, linted with ESLint, and gated by lefthook pre-commit hooks and a CI-driven test/build/publish pipeline.

Code Quality - src/__tests__/ contains 32 test files covering the parser, compiler, matcher, and Unicode handling, exercising the engine against the same edge cases RE2’s Go implementation targets. Code is organized one class per file with names mirroring the Go/Java RE2 lineage (RE2Flags, PublicFlags, CharClass), which keeps the port easy to cross-reference against upstream RE2 behavior.

API Design - Installation is a single npm install re2js, and the API surface intentionally echoes java.util.regex/RE2 conventions (RE2JS.compile(pattern).matcher(input)), which lowers the learning curve for anyone coming from Go, Java, or RE2-family engines, at the cost of feeling slightly less idiomatic than JavaScript’s native RegExp for JS-only developers.

Used by 6 apps in this directory

TypeScript
86%
MIT

Agents Observe

Developer Tools

652

A real-time, fully local observability dashboard for Claude Code and Codex agent sessions — filtering, search, session replay, and token/cost breakdowns via an auto-starting MCP server.

View details
71
Repo Health
67
Technical
77
Dependency
Built with
TypeScript86%
JavaScript11%
Updated 4 weeks ago
TypeScript
97%
Other

Kibana

Analytics · Monitoring

21,251

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
68
Dependency
Built with
TypeScript97%
Updated today
Python
55%
Other

PostHog

Analytics · Monitoring · Developer Tools

37,777

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
67
Dependency
Built with
Python55%
TypeScript36%
Updated today
TypeScript
92%
AGPL 3.0

RSSHub

Automation · Social Media

45,802

Turn any website into an RSS feed — social media, streaming platforms, and niche sites all become subscribable in seconds.

View details
83
Repo Health
82
Technical
74
Dependency
Built with
TypeScript92%
Updated yesterday
TypeScript
97%
Apache 2.0

Unleash

Developer Tools · Devops · Ab Testing Experimentation

13,746

The open-source feature management platform that lets you ship code to production and control who sees it — without redeploying.

View details
91
Repo Health
84
Technical
72
Dependency
Built with
TypeScript97%
Updated today
Python
57%
Apache 2.0

Zulip

Team Chat

25,729

Topic-based team chat that brings the structure of email threads to real-time messaging, so distributed teams never lose context across hundreds of concurrent conversations.

View details
96
Repo Health
86
Technical
68
Dependency
Built with
Python57%
TypeScript19%
JavaScript10%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search