18 releases (9 breaking)

0.10.1 Sep 2, 2024
0.10.0 May 29, 2024
0.9.1 Apr 2, 2024
0.9.0 Feb 26, 2024
0.1.3 May 26, 2020

#51 in Text processing

Download history 150752/week @ 2024-08-18 143636/week @ 2024-08-25 131571/week @ 2024-09-01 161819/week @ 2024-09-08 136233/week @ 2024-09-15 168395/week @ 2024-09-22 161865/week @ 2024-09-29 199612/week @ 2024-10-06 175743/week @ 2024-10-13 243683/week @ 2024-10-20 281681/week @ 2024-10-27 206913/week @ 2024-11-03 206360/week @ 2024-11-10 177942/week @ 2024-11-17 123389/week @ 2024-11-24 110868/week @ 2024-12-01

624,443 downloads per month
Used in 332 crates (217 directly)

MIT/Apache

1.5MB
38K SLoC

regress - REGex in Rust with EcmaScript Syntax

oh no why

Introduction

regress is a backtracking regular expression engine implemented in Rust, which targets JavaScript regular expression syntax. See the crate documentation for more.

It's fast, Unicode-aware, has few dependencies, and has a big test suite. It makes fewer guarantees than the regex crate but it enables more syntactic features, such as backreferences and lookaround assertions.

Fun Tools

The regress-tool binary can be used for some fun.

You can see how things get compiled with the dump-phases cli flag:

> cargo run 'x{3,4}' 'i' --dump-phases

You can run a little benchmark too, for example:

> cargo run --release -- 'abcd' 'i' --bench ~/3200.txt

Want to contribute?

This was my first Rust program so no doubt there is room for improvement.

There's lots of stuff still missing, maybe you want to contribute?

Currently Missing Features

  • An API for replacing a string while substituting in capture groups (e.g. with $1)
  • An API for escaping a string to make it a literal
  • Implementing std::str::pattern::Pattern

Missing Performance Optimizations

  • Anchored matches like ^abc still perform a string search. We should compute whether the whole regex is anchored, and optimize matching if so.
  • Non-greedy loops like .*? will eagerly compute their maximum match. This doesn't affect correctness but it does mean they may match more than they should.
  • Pure literal searches should use Boyer-Moore or etc.
  • There are lots of vectorization opportunities.

Dependencies

~2MB
~30K SLoC