package re

  1. Overview
  2. Docs
RE is a regular expression library for OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

1.7.1.tar.gz
sha256=eb18382d63459b0a4065315ce6fef854bc99152aec2b557bb8a43e664e6679e8
md5=0e45743512b7ab5e6b175f955dc72002

doc/re.posix/Re_posix/index.html

Module Re_posix

References:

Example of how to use this module (to parse some IRC logs):

type msg = {
  time:string;
  author:string;
  content:string;
}

let re = Re.compile (Re_posix.re "([^:].*:[^:]*:[^:]{2})<.([^>]+)> (.+)$")

(* parse a line *)
let match_line line =
  try
    let substrings = Re.exec re line in
    let groups = Re.get_all substrings in
    (* groups can be obtained directly by index within [substrings] *)
    Some {time=groups.(1); author=groups.(2); content=groups.(3)}
  with Not_found ->
    None (* regex didn't match *)

XXX Character classes

exception Parse_error
exception Not_supported

Errors that can be raised during the parsing of the regular expression

type opt = [
  1. | `ICase
  2. | `NoSub
  3. | `Newline
]
val re : ?opts:opt list -> string -> Re.t

Parsing of a Posix extended regular expression

val compile : Re.t -> Re.re

Regular expression compilation

val compile_pat : ?opts:opt list -> string -> Re.re

compile r is defined as Re.compile (Re.longest r)

OCaml

Innovation. Community. Security.