ferroni 2.8.0

Oniguruma regex in pure Rust, with a TextMate scanner, portable prepared Eager archives, and no C toolchain
Documentation
<!-- This file is generated by mdtheme. Edit README.md.src instead. -->

Part of [Ferramenta](https://ferramenta.dev), a family of Rust tools.

# Ferroni — Oniguruma regex in pure Rust

[![Powered by Sebastian Software](https://img.shields.io/badge/Powered_by-Sebastian_Software-005164?style=flat)](https://oss.sebastian-software.com) [![crates.io](https://img.shields.io/crates/v/ferroni?style=flat-square&logo=rust&label=crates.io)](https://crates.io/crates/ferroni)
[![docs.rs](https://img.shields.io/docsrs/ferroni?style=flat-square&logo=docsdotrs&label=docs.rs)](https://docs.rs/ferroni)
[![CI](https://img.shields.io/github/actions/workflow/status/sebastian-software/ferroni/ci.yml?branch=main&style=flat-square&logo=github&label=CI)](https://github.com/sebastian-software/ferroni/actions)
[![Coverage gate at least 87 percent](https://img.shields.io/badge/coverage%20gate-%E2%89%A5%2087%25-blue?style=flat-square)](https://github.com/sebastian-software/ferroni/blob/main/.github/workflows/ci.yml)
[![MSRV 1.94](https://img.shields.io/badge/MSRV-1.94-blue?style=flat-square&logo=rust)](CONTRIBUTING.md#getting-started)
[![License](https://img.shields.io/badge/license-BSD--2--Clause-blue?style=flat-square)](https://github.com/sebastian-software/ferroni/blob/main/LICENSE)

**Bring your Oniguruma patterns to Rust.**
Keep the look-behind, backreferences and recursion your patterns rely on,
with a familiar `Regex` API and a TextMate scanner built for syntax
highlighters. Cargo handles the build, including WebAssembly. No C compiler,
no bindgen, just Rust.

## Quick start

```bash
cargo add ferroni
```

```rust
use ferroni::prelude::*;

fn main() -> Result<(), RegexError> {
    // A look-behind and named groups: Oniguruma syntax, a familiar API.
    let re = Regex::new(r"(?<=Date: )(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})")?;

    let caps = re.captures("Date: 2026-02-12").unwrap();
    assert_eq!(caps.get(0).unwrap().as_str(), "2026-02-12");
    assert_eq!(caps.name("year").unwrap().as_str(), "2026");
    Ok(())
}
```

That's a look-behind and three named captures, ready to use in your Rust
project. Compile once, then reuse the pattern across your searches.

| What are you building? | Start here |
| --- | --- |
| Matching, extraction or replacement | [Getting started]https://ferroni.dev/guide/getting-started |
| A tokenizer or TextMate highlighter | [Scanner guide]https://ferroni.dev/guide/scanner |
| A highlighter that loads the same patterns on every start | [Prepared Eager archives]https://ferroni.dev/guide/precompiled-eager |
| An application moving from `regex` or `onig` | [API mapping and default differences]https://ferroni.dev/guide/coming-from-regex |

## Why Ferroni

**Give your patterns room to work.** Look-around, backreferences, recursive
subexpressions and all twelve Oniguruma syntax modes are included. Ferroni
is the only Rust engine among those checked with every feature in the
[feature matrix](https://ferroni.dev/perf/regex-workloads#syntax-coverage).
When you need linear-time matching for user-supplied patterns, Rust's
[`regex`](https://crates.io/crates/regex) crate is a great fit.

**Serious speed for patterns you reuse.** In the published regex workloads,
Ferroni matches 2.5–3.3× faster than C Oniguruma in the family-weighted
aggregate after compilation, without generating machine code at runtime.
The tasks come from Django, Rails, WordPress and other projects. Results
vary by task. C still compiles patterns faster in the aggregate, so check
first-use costs when you rarely reuse a pattern. See the
[benchmark summary](https://ferroni.dev/perf/regex-workloads) and
[full results](benches/production_results/README.md) for the measured workloads,
platforms and tradeoffs.

**Build the highlighter you have in mind.** Ferroni's Scanner follows
vscode-oniguruma's scanning model, including UTF-16 offsets for editor
integrations. It finds the next match across a set of patterns; your TextMate
runtime handles grammar rules and scopes. [Ferriki](https://ferriki.dev)
builds a Shiki-compatible highlighter on it.

**Prepare scanner groups once. Reuse them across starts.** With the optional
`precompiled-eager` feature, export compiled programs and prepared Eager group
instructions as a portable pair. Ship them with your application, embed them,
or serve them as assets for compatible native and WebAssembly builds. Requested
records decode on demand; missing or incompatible groups use normal Eager
preparation. See the [prepared Eager guide](https://ferroni.dev/guide/precompiled-eager)
for generation, loading and the work that remains local.

**An established engine, a Rust future.** Oniguruma's C project closed in
April 2025. Ferroni continues it, ported function by function, and
[passes all 2,974 upstream UTF-8 tests](https://ferroni.dev/guide/compatibility).
Buffer and string processing use safe Rust. The
[10 unsafe sites](https://ferroni.dev/adr/002-unsafe-code-policy) are confined
to links between parse-tree nodes.

## Scope

Ferroni covers ASCII and UTF-8, two of Oniguruma's 29 encodings, and leaves
out the POSIX and GNU APIs. It backtracks like C Oniguruma, so give searches
over untrusted input a time or retry limit. On `wasm32-unknown-unknown`, the
browser target, use a retry limit; that target has no clock for a time limit.
See [compatibility](https://ferroni.dev/guide/compatibility) and
[untrusted input](https://ferroni.dev/guide/untrusted-input).

## Documentation

- [Getting started]https://ferroni.dev/guide/getting-started — your first match, captures, replacement, options and errors.
- [Scanner guide]https://ferroni.dev/guide/scanner — tokenization loops, UTF-16 positions and shared compiled patterns.
- [Prepared Eager archives]https://ferroni.dev/guide/precompiled-eager — move reusable scanner preparation into your build step and share it across starts.
- [API reference]https://docs.rs/ferroni — every public type and function.
- [Regex benchmarks]https://ferroni.dev/perf/regex-workloads — the speed summary, source projects, method and feature matrix.
- [Benchmark results]benches/production_results/README.md — per-platform aggregates, with every case and timing in [`publication.json`]benches/production_results/publication.json and tiktoken pre-tokenization in [`additional_results`]benches/additional_results/README.md.
- [Migrating to 2.0]https://ferroni.dev/guide/migrating-to-2 — breaking changes with before and after code.

## Project status and contributing

Ferroni's Oniguruma compatibility scope is complete and maintained. Bug fixes,
Unicode updates, toolchain upkeep and security fixes remain in scope. Rust-only
scanner optimizations and startup reuse extend the port without expanding its
syntax or encoding scope. See the
[project status](https://ferroni.dev/#project-status) for the maintenance
scope.

[CONTRIBUTING.md](CONTRIBUTING.md) covers builds, tests and benchmarks; pull
requests keep the
[structural parity with C Oniguruma](https://ferroni.dev/adr/001-one-to-one-parity-with-c-original)
that the port is built on. Report vulnerabilities privately as described in
[SECURITY.md](SECURITY.md).

## Acknowledgments and license

Built on [K. Kosako's Oniguruma](https://github.com/kkos/oniguruma) and
Microsoft's [vscode-oniguruma](https://github.com/microsoft/vscode-oniguruma)
Scanner API and tests. Ferroni is an independent continuation and is not
affiliated with or endorsed by Oniguruma's original author.

[BSD-2-Clause](LICENSE), inherited from the Oniguruma source this port is
based on.

### <a href="https://ferramenta.dev"><img src="https://raw.githubusercontent.com/sebastian-software/ferramenta/main/app/assets/brand/logo-light.svg" width="24" height="24" alt="" /> More from Ferramenta</a>

[Ferramenta](https://ferramenta.dev) — A family of Rust tools.

**Engines**

| Tool | Job |
| --- | --- |
| [ferriki]https://ferriki.dev | Shiki-compatible syntax highlighting |
| [ferromark]https://ferromark.dev | Markdown to HTML, sanitized by default |
| [ferrolex]https://github.com/sebastian-software/ferrolex | Spell checking for text and code |
| [ferrocat]https://ferrocat.dev | Translation catalog engine |
| [ferralk]https://github.com/sebastian-software/ferralk | Glob matching and parallel filesystem walking |
| [ferrugo]https://github.com/sebastian-software/ferrugo | PDF previews for untrusted files |

**Applications**

| Tool | Job |
| --- | --- |
| [palamedes]https://palamedes.dev | Internationalization for TypeScript applications |
| [dalo]https://dalo.sh | Your team's agent setup, versioned like code |

---

<p align="center">
  <a href="https://oss.sebastian-software.com"><img src="https://raw.githubusercontent.com/sebastian-software/oss.sebastian-software.com/main/app/assets/logo-software.svg" alt="Sebastian Software" width="160" /></a><br />
  TypeScript, React &amp; Rust consulting<br />
  Experts in Agentic Software Development<br />
  <a href="https://sebastian-software.de">Work with us</a> · <a href="https://oss.sebastian-software.com">More open source</a>
</p>

<p align="center">Copyright &copy; 2026 Sebastian Software GmbH</p>