package aho-corasick
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
md5=f1d1c262b14a9ab81e6933c5cb62b545
sha512=369d9b7fe1cd2c4af1eb20739f357ed1259f05590b53c7b3e77da9138bd50155ce966a1a2a521c70c598092c4d7d788c02bc6cce97a65eda69985d2d4a132952
Description
Multi-pattern matching over byte strings in pure OCaml, with no runtime dependencies beyond the standard library. Supports overlapping search, lazy iteration, leftmost-longest selection, replacement, ASCII case folding, and chunked streaming in three match modes. Automata are immutable and reusable. Search is linear in the input plus matches examined; leftmost-longest selection uses lookahead bounded by the longest pattern.
README
ocaml-aho-corasick
Find many literal patterns in one pass over a byte string. Pure OCaml, with no runtime dependencies beyond the standard library.
Supports overlapping matches, lazy iteration, leftmost-longest selection, replacement, ASCII case folding, and streaming across chunk boundaries.
Install
Requires OCaml 4.14 or newer and Dune 3.14 or newer.
Until v0.1.1 is published to opam, install from this checkout:
opam install .After publication:
opam install aho-corasickAdd (libraries aho-corasick) to your executable or library's Dune stanza.
Quick start
let matcher = Aho_corasick.build [ "he"; "she"; "his"; "hers" ]
let matches = Aho_corasick.find_all matcher "ushers"
(* she: 1..4, he: 2..4, hers: 2..6 *)
let words = Aho_corasick.build [ "cat"; "dog" ]
let replaced =
Aho_corasick.replace_all words ~f:(fun _ -> "[pet]") "cat and dog"
(* "[pet] and [pet]" *)Each match has a pattern index into the original pattern list, a start byte offset, and an exclusive stop byte offset. Build once and reuse the immutable matcher.
find_all and find_iter include overlaps. find_leftmost_longest and replace_all choose non-overlapping matches, preferring the longest match at the earliest position. mem stops at the first match.
Matching uses bytes, including for UTF-8. ~ignore_case:true folds ASCII letters only. Empty pattern lists are allowed; empty strings as patterns raise Invalid_argument.
Documentation
- Usage and streaming examples
- Match rules and performance
- Compatibility and differential testing
- Reproducible benchmarks and published results
- Building and testing
- Release procedure and changelog
- Website and API reference
License
MIT.
Dev Dependencies (4)
-
odoc
with-doc -
qcheck-alcotest
with-test & >= "0.25" -
qcheck-core
with-test & >= "0.25" -
alcotest
with-test & >= "1.5.0"
Optional Dependencies
None
Used by
None
Conflicts
None
Build status
Results of building aho-corasick with each compiler on check.ci.ocaml.org, run of against opam-repository 78c202b. All results for this package.
Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.
| Version | OCaml 4.11 | OCaml 4.14 | OCaml 5.2 | OCaml 5.4 | OCaml 5.5 |
|---|---|---|---|---|---|
| 0.1.1 (this version) | n/a | good | good | good | good |
- good Package successfully built
- partial One of the dependencies failed to build
- bad Package failed to build
- n/a Package is not available in this environment
- internal Internal failure