# r/rust Post

## Title

rgx — a terminal regex tester with 3 engines, built with ratatui + regex-syntax

## Body

I built **rgx**, a TUI for testing regex patterns without leaving the terminal.

**GitHub:** https://github.com/brevity1swos/rgx
**Install:** `cargo install rgx-cli` or `brew install brevity1swos/tap/rgx`

### What it does

- Live matching that updates on every keystroke
- 3 regex engines — Rust `regex`, `fancy-regex` (lookaround/backrefs), PCRE2 — switch with Ctrl+E
- Capture group highlighting with named group support
- Plain-English explanations generated by walking the `regex-syntax` HIR AST
- Replace/substitution with live preview (`$1`, `${name}`, `$0`)
- Syntax highlighting, undo/redo, pattern history, mouse support, whitespace visualization

### Where it's actually useful

Being honest: if regex101.com works for you, it'll keep working — it has more engines, shareable links, and a community pattern library. rgx is for a narrower set of situations:

- **Testing against the Rust `regex` crate directly** — regex101 doesn't have this engine, so you can't know if your pattern will compile with Rust's linear-time guarantee
- **Remote/offline work** — SSH sessions, containers, air-gapped environments
- **Pipeline use** — `echo "data" | rgx -p '\d+'` prints matches to stdout and exits (exit codes: 0 = match, 1 = no match, 2 = error). Or use interactively and press Ctrl+O to output

### Architecture bits that might interest r/rust

The engine switching uses a `RegexEngine` trait (compile) and a `CompiledRegex` trait (find matches). Each engine implements both, and an `EngineKind` enum + factory selects the active one. Adding a new engine is ~100 lines of trait impls plus a variant.

PCRE2 is behind a feature flag (`pcre2-engine`) so `cargo install rgx-cli --no-default-features` gives you a fully static binary with zero C dependencies.

The `regex-syntax` crate's HIR made the explanation feature straightforward — visitor pattern over the AST, formatter turns it into English.

Feedback welcome, especially on the TUI patterns and engine abstraction.
