#sys #onig #oniguruma

sys onig_sys

The onig_sys crate contains raw rust bindings to the oniguruma library. This crate exposes a set of unsafe functions which can then be used by other crates to create safe wrappers around Oniguruma. You probably don’t want to link to this crate directly; instead check out the onig crate.

35 releases (stable)

69.2.0 Aug 8, 2019
69.1.0 Jan 12, 2019
69.0.0 Sep 6, 2018
68.2.1 Sep 5, 2018
0.6.0 Jan 31, 2016
Download history 4813/week @ 2019-10-04 5188/week @ 2019-10-11 4899/week @ 2019-10-18 5166/week @ 2019-10-25 4957/week @ 2019-11-01 4972/week @ 2019-11-08 4975/week @ 2019-11-15 6424/week @ 2019-11-22 5340/week @ 2019-11-29 5524/week @ 2019-12-06 6203/week @ 2019-12-13 4389/week @ 2019-12-20 4728/week @ 2019-12-27 5713/week @ 2020-01-03 5924/week @ 2020-01-10

22,656 downloads per month
Used in 29 crates (3 directly)

MIT license

75K SLoC

C 74K SLoC // 0.0% comments Python 1K SLoC // 0.1% comments Rust 215 SLoC // 0.1% comments Automake 169 SLoC // 0.0% comments Shell 61 SLoC // 0.1% comments C++ 19 SLoC // 0.4% comments Batch 15 SLoC

Rust Onig

Build Status Build status dependency status

Rust bindings for the Oniguruma regex library, a powerful and mature regular expression library with support for a wide range of character sets and language syntaxes. Oniguruma is written in C. This repository provides two crates: onig-sys which provides the raw Rust FFI bindings, and onig, which provides a safe Rust wrapper around them.


Check out the module documentation to find out all the features that are available. To see some example usage of this crate take a look a the examples folder. The examples can be run from the command line with cargo run --example <examplename>.

Getting Started

Add the following to your Cargo.toml file:

onig = "4.3"

Add the following extern to your crate root:

extern crate onig;

You can compile simple regular expressions with Regex::new, check if the pattern matches an entire &str with Regex::is_match and find matches within a &str with Regex::find. The onig crate also supplies more powerful versions of these methods which expose the wide range of options Oniguruma provides.

use onig::*;

let regex = Regex::new("e(l+)").unwrap();
for (i, pos) in regex.captures("hello").unwrap().iter_pos().enumerate() {
    match pos {
         Some((beg, end)) =>
             println!("Group {} captured in position {}:{}", i, beg, end),
         None =>
             println!("Group {} is not captured", i)


If a version of Oniguruma can be found by pkg-config then that will be used. If not then Oniguruma will be compiled from source and linked to the onig-sys crate.

By default rust-onig will be statically linked to libonig. If you would rather that dynamic linking is used then the environment variables RUSTONIG_STATIC_LIBONIG and RUSTONIG_DYNAMIC_LIBONIG can be set. On *nix:


Or Windows:

> cargo build


Sometimes it's useful to debug how Oniguruma parses, compiles, optimizes or executes a particular pattern.

When activating the print-debug feature for this crate, Oniguruma is compiled with debugging. Note that it's a compile-time setting, so you also need to make rust-onig not use the system Oniguruma by using RUSTONIG_SYSTEM_LIBONIG.

With all that combined, here's an example command to debug the pattern a|b:

RUSTONIG_SYSTEM_LIBONIG=0 cargo run --features print-debug --example capturedump 'a|b'

Supported Rust Versions

Rust Onig supports Rust 1.33.0 or later on Windows and 1.32.0 or later for Linux and macOS. If the minimum supported rust version is changed then the minor version number will be increased. That is v4.2.x should always compile with the same version of the compiler.

Rust-Onig is Open Source

The contents of this repository are distributed under the MIT license. See LICENSE for more details. If you'd like to contribute take a look at our open easy issues.


~32K SLoC