A pure OCaml regular expression library supporting Perl, POSIX, Emacs, and glob patterns with DFA-based matching.
Re is a regular expression library for OCaml that provides multiple regex styles (Perl, POSIX, Emacs, shell globbing) in a pure OCaml implementation. It uses deterministic finite automaton (DFA) compilation for efficient, linear-time matching, avoiding catastrophic backtracking common in other libraries. This makes it suitable for performance-sensitive applications where predictable runtime is critical.
OCaml developers who need reliable and fast regular expression matching, particularly those working on performance-sensitive applications like file synchronization tools, text processing pipelines, or systems where avoiding exponential backtracking is essential.
Developers choose Re over alternatives like PCRE for its predictable linear-time performance due to DFA-based matching, which prevents exponential runtime in edge cases. It also offers a unique combination of multiple regex styles in one library and provides a PCRE-compatible interface for easier code porting.
Pure OCaml regular expressions, with support for Perl and POSIX-style strings
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses DFA-based matching that ensures linear time in string length, avoiding exponential backtracking seen in libraries like PCRE, as demonstrated in timing tests with large strings.
Supports Perl, POSIX, Emacs, and shell globbing dialects in one library, allowing flexibility without switching tools, as detailed in the features section.
Provides a Re.Pcre module for easier porting from PCRE with minimal code changes, facilitating migration for existing projects, as noted in the README.
When compiled natively, matching is extremely fast and often outperforms PCRE for many patterns, evidenced by benchmarks like scanning large strings for ignore rules.
Lacks back-references and look-ahead/look-behind assertions, which are critical for some regex tasks, limiting its use for complex pattern matching as admitted in the README.
DFA compilation is slower than backtracking libraries like PCRE, making it less ideal for applications with frequent new pattern compilations, as highlighted in the performances section.
Matching is much slower when compiled to bytecode versus native code, affecting development and deployment in bytecode-heavy environments, as explicitly stated in the README.