regexr

Library Listed

A high-performance regex engine built from scratch with JIT compilation and SIMD acceleration

Checked · Sources

Downloads
8,809
Dependents
4
Stars
28
Forks
1
Contributors
2
Commits
236
Latest release
0.6.2 ·

About

From the project README ·

regexr

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:

Featureregexrregexfancy-regexpcre2
Lookarounds ((?=...), (?<=...), (?!...))YesNoYesYes
BackreferencesYesNoYesYes
JIT compilationYes (x86-64, aarch64)NoNoYes
No C library dependencyYesYesYesNo (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 nameUsed for
ShiftOrPatterns up to 64 character positions
ShiftOrWidePatterns from 65 to 256 character positions
LazyDfaMost other patterns
EagerDfaFully built form of LazyDfa, used when the build fits its budget
PikeVmLookarounds, non-greedy quantifiers, and boundary-guarded empty matches
TaggedNfaUnicode codepoint classes, such as \p{L}
BacktrackingVmBackreferences
CodepointClassCodepoint-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

FeatureDefaultEnables
simdOnSIMD literal search (AVX2 on x86-64, NEON on aarch64)
jitOffJIT compilation on x86-64 and aarch64
fullOffjit 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-unknown builds 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):

Performance Heatmap

Documentation

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.

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.

regexr beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
regexr This page Listed

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
rust_tokenizers Listed Dormant

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 days
  • dormancy: last activity 2026-11-06, 3 days ago, E = 365: active
  • featured: 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
Adoption1 active dependents, 1 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents1crates.io database dumpYes
New dependents (365 days)1crates.io database dumpYes
Peak active dependents1crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 3 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-11-06GitHub repositoryYes
Latest release2026-11-06crates.io database dumpYes
First release2026-03-15crates.io database dumpYes
Latest version0.6.2crates.io database dumpYes
Days the oldest outside issue waits for a reply0GitHub repositoryYes
Maintainer replies over 365 days4GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution17 releases, 8,809 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases17crates.io database dumpYes
Downloads over 30 days8809crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository28 stars, 1 forks, 2 contributors, 236 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars28GitHub repositoryYes — one part of the repository route
GitHub forks1GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account2GitHub contributorsYes — one part of the repository route
Commits on the default branch236GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseApache-2.0 OR MITcrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesNo native code foundcrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly4crates.io database dumpNo

Corrections and review history

Report a correction

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.