Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


Pure OCaml regular expressions, with support for Perl and POSIX-style strings

Subscribe to updates I use ocaml-re

Statistics on ocaml-re

Number of watchers on Github 102
Number of open issues 20
Average time to close an issue about 2 months
Main language OCaml
Average time to merge a PR 6 days
Open pull requests 6+
Closed pull requests 7+
Last commit over 1 year ago
Repo Created over 7 years ago
Repo Last Updated over 1 year ago
Size 671 KB
Organization / Authorocaml
Latest Release1.7.3
Page Updated
Do you use ocaml-re? Leave a review!
View open issues (20)
View ocaml-re activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating ocaml-re for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


Re is a regular expression library for OCaml. Build Status


This library has been written by Jerome Vouillon ( It can be downloaded from

Bug reports, suggestions and contributions are welcome.


The following styles of regular expressions are supported:

  • Perl-style regular expressions (module Re.Perl);
  • Posix extended regular expressions (module Re_posix);
  • Emacs-style regular expressions (module Re.Emacs);
  • Shell-style file globbing (module Re_glob).

It is also possible to build regular expressions by combining simpler regular expressions (module Re).

The most notable missing features are back-references and look-ahead/look-behind assertions.

There is also a subset of the PCRE interface available in the Re.pcre library. This makes it easier to port code from that library to Re without any changes beyond replacing the pcre findlib package with re.pcre.


The matches are performed by lazily building a DFA (deterministic finite automaton) from the regular expression. As a consequence, matching takes linear time in the length of the matched string.

The compilation of patterns is slower than with libraries using back-tracking, such as PCRE. But, once a large enough part of the DFA is built, matching is extremely fast.

Of course, for some combinations of regular expression and string, the part of the DFA that needs to be build is so large that this point is never reached, and matching will be slow. This is not expected to happen often in practice, and actually a lot of expressions that behaves badly with a backtracking implementation are very efficient with this implementation.

The library is at the moment entirely written in OCaml. As a consequence, regular expression matching is much slower when the library is compiled to bytecode than when it is compiled to native code.

Here are some timing results (Pentium III 500Mhz):

  • Scanning a 1Mb string containing only as, except for the last character which is a b, searching for the pattern aa?b (repeated 100 times):
    • RE: 2.6s
    • PCRE: 68s
  • Regular expression example from [1]
    • RE: 0.43s
    • PCRE: 3.68s

[1] this page is no longer up but is available via the Internet Archive

  • The large regular expression (about 2000 characters long) that Unison uses with my preference file to decide whether a file should be ignored or not. This expression is matched against a filename about 20000 times.
    • RE: 0.31s
    • PCRE: 3.7s However, RE is only faster than PCRE when there are more than about 300 filenames.
ocaml-re open issues Ask a question     (View All Issues)
  • almost 3 years Substring matching + lookaround weird interaction
  • almost 3 years Clearer documentation for Re.eol
  • about 3 years Re_str supports more patterns than necessary.
  • about 3 years Installation fails whenever ocamldoc is absent
  • over 3 years host doc on github
  • over 3 years Support for \n and positive/negative lookahead in Pcre?
  • over 3 years Re.split odd behaviour with separator at beginning/end
  • almost 4 years Negation in Regular Expressions
  • about 4 years Problems building Re with MSVC toolchain under Windows
  • about 4 years `compl` deemed dangerous
  • over 4 years Streaming Re
  • over 4 years Vim style regular expressions
  • almost 5 years [Feature Request] Unicode support
ocaml-re open pull requests (View All Pulls)
  • Miscellaneous clean-up
  • [RFC] Add Unicode support
  • add Re.Group.pp
  • Use real laziness for Re_automata.state
  • Port to jbuilder take 2
  • Re-organization with jbuilder
ocaml-re list of languages used
ocaml-re latest release notes

1.7.3 (05-Mar-2018)

  • Remove dependency on bytes package (#155)

1.7.2 (01-Mar-2018)

  • Deprecate all Re_* modules. Re_x is now available as Re.X
  • Deprecate all re.x sub libraries. Those are all available as Re.X
  • Make all function in Re.Str tail recursive.
  • Fix 4.00.1 compatibilty with tests.
Other projects in OCaml