regexr
Library Listed
A high-performance regex engine built from scratch with JIT compilation and SIMD acceleration
- Downloads
- 8,809
- Dependents
- 4
- Stars
- 28
- Forks
- 1
- Contributors
- 2
- Commits
- 236
- Latest release
- 0.6.2 ·
About

A Rust regex engine with lookarounds, backreferences, and JIT compilation.
Built for LLM tokenizer patterns. Pure Rust: lookarounds and JIT compilation need no C toolchain or system library.
Docs · Crate · Engines · Features · Example · Contributing
What is regexr
regexr is a regex engine for Rust, written from scratch. It was created as the regex backend for splintr, an LLM tokenizer. It is a Rust alternative to PCRE2 for patterns that need lookarounds and backreferences. It needs Rust 1.83 or newer and no Python.
Use regexr when a pattern needs one of these features:
| Feature | regexr | regex | fancy-regex | pcre2 |
|---|---|---|---|---|
Lookarounds ((?=...), (?<=...), (?!...)) | Yes | No | Yes | Yes |
| Backreferences | Yes | No | Yes | Yes |
| JIT compilation | Yes (x86-64, aarch64) | No | No | Yes |
| No C library dependency | Yes | Yes | Yes | No (links libpcre2) |
regex omits lookarounds and backreferences on purpose. Use it for everything else.
Patterns without backreferences run on automaton engines, which report the match in time linear in the input. Backreferences run on a backtracking engine with a step budget. See Bounded execution.
Not supported yet:
Read the full README
- Atomic groups
(?>...)and possessive quantifiers. Both return a parse error. - The
\N{NAME}named Unicode escape. It returns a parse error.
Quick Start
Add the crate with cargo add regexr. For JIT and SIMD, enable the full feature:
cargo add regexr --features full
use regexr::Regex;
let re = Regex::new(r"\w+").unwrap();
assert!(re.is_match("hello"));
// Find the first match
if let Some(m) = re.find("hello world") {
println!("Found: {}", m.as_str()); // "hello"
}
// Find all matches
for m in re.find_iter("hello world") {
println!("{}", m.as_str());
}
Usage
Capture Groups
use regexr::Regex;
let re = Regex::new(r"(\w+)@(\w+)\.(\w+)").unwrap();
let caps = re.captures("user@example.com").unwrap();
println!("{}", &caps[0]); // "user@example.com"
println!("{}", &caps[1]); // "user"
Named Captures
use regexr::Regex;
let re = Regex::new(r"(?P<user>\w+)@(?P<domain>\w+\.\w+)").unwrap();
let caps = re.captures("user@example.com").unwrap();
println!("{}", &caps["user"]); // "user"
println!("{}", &caps["domain"]); // "example.com"
JIT Compilation
Enable JIT for a pattern that runs many times. JIT needs the jit feature.
use regexr::RegexBuilder;
let re = RegexBuilder::new(r"\w+")
.jit(true)
.build()
.unwrap();
assert!(re.is_match("hello"));
Prefix Optimization
For patterns with many literal alternatives, such as keyword lists in tokenizers:
use regexr::RegexBuilder;
let re = RegexBuilder::new(r"(function|for|while|if|else|return)")
.optimize_prefixes(true)
.build()
.unwrap();
assert!(re.is_match("function"));
Replacement
use regexr::Regex;
let re = Regex::new(r"\d+").unwrap();
assert_eq!(re.replace("abc 123 def", "NUM"), "abc NUM def");
assert_eq!(re.replace_all("abc 123 def 456", "NUM"), "abc NUM def NUM");
Bounded Execution
Backreferences can take exponential time. Set a step budget with RegexBuilder::backtrack_limit:
use regexr::RegexBuilder;
let re = RegexBuilder::new(r"(a+)\1")
.backtrack_limit(1_000_000)
.build()
.unwrap();
match re.try_is_match("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa!") {
Ok(matched) => println!("matched: {matched}"),
Err(e) => println!("budget exhausted: {e}"),
}
try_find, try_captures, and try_is_match return an error when the budget runs out. find, captures, and is_match do not report that case.
Engine Selection
regexr picks one engine for each pattern. Call Regex::engine_name() to read the choice.
Engines without jit (default simd build):
| Engine name | Used for |
|---|---|
ShiftOr | Patterns up to 64 character positions |
ShiftOrWide | Patterns from 65 to 256 character positions |
LazyDfa | Most other patterns |
EagerDfa | Fully built form of LazyDfa, used when the build fits its budget |
PikeVm | Lookarounds, non-greedy quantifiers, and boundary-guarded empty matches |
TaggedNfa | Unicode codepoint classes, such as \p{L} |
BacktrackingVm | Backreferences |
CodepointClass | Codepoint-class matching |
With the jit feature on x86-64 or aarch64, the matching JIT engines are Jit, JitShiftOr, TaggedNfaJit, and BacktrackingJit.
Capture extraction uses a one-pass engine when the pattern allows it. docs/architecture.md explains the selection rules in full.
Feature Flags
| Feature | Default | Enables |
|---|---|---|
simd | On | SIMD literal search (AVX2 on x86-64, NEON on aarch64) |
jit | Off | JIT compilation on x86-64 and aarch64 |
full | Off | jit and simd |
cargo build # simd (default)
cargo build --features full # jit + simd
cargo build --no-default-features # scalar search, no JIT
cargo check --no-default-features --target wasm32-unknown-unknown
Platform Support
- JIT: x86-64 and aarch64. Windows x86-64 uses the Windows calling convention.
- SIMD: AVX2 on x86-64, detected at run time. NEON on aarch64. A scalar fallback runs on every other target.
- WASM:
wasm32-unknown-unknownbuilds with--no-default-features. CI checks this build.
Benchmarks
Run cargo bench --bench competitors to compare regexr with regex, fancy-regex, and pcre2. This README does not publish benchmark numbers. Results depend on the machine.
Speedup relative to the regex crate (higher is better):

Documentation
- docs/architecture.md: engine architecture and selection rules
- docs/features.md: feature reference
- docs/engine_structure.md: engine module layout
Citation
@software{regexr2025,
author = {Syah, Farhan},
title = {regexr: A Rust Regex Engine with JIT Compilation for LLM Tokenization},
year = {2025},
url = {https://github.com/ml-rust/regexr},
note = {Rust regex engine with lookaround support and JIT compilation}
}
Contributing
Contributions are welcome. See CONTRIBUTING.md for conventions and checks.
Questions and design discussion happen on Discord.
License
Licensed under either of MIT or Apache-2.0, at your option.
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- None found
- No native code found
- Python bindings
- No Python binding crate found
- License
- Apache-2.0 OR MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
A high-performance regex engine built from scratch with JIT compilation and SIMD acceleration |
8,809 downloads over 30 days | 4 | 28 | 0.6.2 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
tiktoken-rs Featured
Library for encoding and decoding with the tiktoken library in Rust |
3,939,182 downloads over 30 days | 449 | 410 | 0.12.1 | GPU support unknown | No native code found | MIT |
|
text-splitter Featured
Split text into semantic chunks, up to a desired chunk size. Supports calculating length by characters and tokens, and is callable from Rust and Python. |
271,174 downloads over 30 days | 56 | 645 | 0.33.1 | GPU support unknown | Binds native code: tree-sitter (feature code), tree-sitter-language (feature code) | MIT |
|
sentencex Listed
Sentence segmentation library with wide language support optimized for speed and utility. |
114,914 downloads over 30 days | 1 | 145 | 0.1.34 | GPU support unknown | No native code found | MIT |
|
High performance tokenizers for Rust Python bindings |
27,821 downloads over 30 days | 12 | 345 | 8.1.1 | GPU support unknown | No native code found | Apache-2.0 |
|
xberg New
High-performance document intelligence library for Rust. Extract text, metadata, and structured data from PDFs, Office documents, images, and 107 formats and 371 programming languages via tree-sitter code intelligence with async/sync APIs. |
26,095 downloads over 30 days | 2 | 9,565 | 1.3.10 | CUDA, Metal | Binds native code: libheif-sys, libz-sys, xberg_libwpd, xberg_tesseract, clipper-sys and 4 more. Build uses a native toolchain: cc, bindgen (feature bindings), cmake (feature build-tesseract), pkg-config (feature dynamic-linking), vcpkg (feature dynamic-linking) | MIT |
Why ListedNo archive, New or Featured rule places it, so it is Listed.
What it lacks for Featured
- It has 1 active dependents and 1 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days. The repository route reads 28 stars, 1 fork and 2 contributors. It needs 4,539 stars, 434 forks and 79 contributors together.
What else the check found
- The last activity is on 6 Nov 2026, 3 days ago. The rules expect an update within 365 days. Dormancy rule
Exact rules: Listed, Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.6.2 base 300, raised to the 365-day floor: E = 365 daysdormancy: last activity 2026-11-06, 3 days ago, E = 365: activefeatured: not featured: active_users 1 < 11 and new_adopters 1 < 9 and repository route stars 28 (needs 4539), forks 1 (needs 434), contributors 2 (needs 79)listed: listed: no archive, new or featured rule applies
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption1 active dependents, 1 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 1 | crates.io database dump | Yes | |
| New dependents (365 days) | 1 | crates.io database dump | Yes | |
| Peak active dependents | 1 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 3 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-11-06 | GitHub repository | Yes | |
| Latest release | 2026-11-06 | crates.io database dump | Yes | |
| First release | 2026-03-15 | crates.io database dump | Yes | |
| Latest version | 0.6.2 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 0 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 4 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution17 releases, 8,809 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 17 | crates.io database dump | Yes | |
| Downloads over 30 days | 8809 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository28 stars, 1 forks, 2 contributors, 236 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 28 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 1 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 2 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 236 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | Apache-2.0 OR MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | No native code found | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 4 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.