Module Cf_regex

module Cf_regex: sig .. end
Regular expression parsing, search and matching.


Overview

This module implements regular expression parsing, search and matching in pure Objective Caml. The grammar for regular expressions is a little unconventional. Instead of using a backslash as the escape character, the backtick character is used instead. This makes it easy to write regular expressions in string literals.

Use any of the following constructions in regular expressions:



Modules

module DFA: Cf_dfa.T  with type S.t = char
The deterministic finite automata on octet character symbols.

Exceptions

exception Error of string
An error parsing the specified string as a regular expression.

Types

type t 
An abstract type representing a regular expression.

Functions

val expr_parse : (char, DFA.x) Cf_parser.t
A parser combinator on character streams that recognizes a regular expression and produces a DFA expression for it.
val expr_of_seq : char Cf_seq.t -> DFA.x
Use expr_of_seq z to evaluate the character sequence z as a regular expression and produce the corresponding DFA expression. Raises Error if the sequence is not a valid expression.
val expr_of_string : string -> DFA.x
Use expr_of_string s to evaluate the string s as a regular expression and produce the corresponding DFA expression. Raises Error if the string is not a valid expression.
val quote : (char, char) Cf_flow.t
A character flow that quotes all the special characters in the input so that the output may be used in a regular expression to match the input exactly.
val unquote : (char, char) Cf_flow.t
A character flow that unquotes all the quoted special characters in the input so that the output may by used in a regular expression to match the specified pattern.
val of_expression : DFA.x -> t
Use of_expression x to produce a regular expression from the DFA expression x.
val of_seq : char Cf_seq.t -> t
Use of_seq z to ingest the whole character sequence z, parse it and produce a regular expression. Raises Error s if the sequence is not a valid regular expression, with s containing the string composed of the characters in the sequence.
val of_string : string -> t
Use of_string s to produce a regular expression from the string s. Raises Error s if the string is not a valid regular expression.
val test : t -> string -> bool
Use test r s to test whether the string s matches the regular expression r.
val search : t -> char Cf_seq.t -> int * int
Use search r z to search the character sequence z for a pattern that matches the regular expression r. Returns (pos, len), where pos is the number of characters into the sequence where the matching sequence begins, and len is the number matching characters.
val separate : t -> char Cf_seq.t -> char Cf_seq.t Cf_seq.t
Use separate r z to map the character sequence z into the sequence of sequences found between matches for the regular expression r.
val split : t -> string -> string list
Use split r s to produce a list of strings by searching s left to right for blocks of characters between patterns that match the regular expression r.
val parse : t -> (char, string) Cf_parser.t
Use parse r to produce a parser that matches the input stream to the regular expression r and returns the corresponding string value.
val parsex : t -> ('a #Cf_parser.cursor, char, string) Cf_parser.X.t
Use parse r to produce a parser that matches the input stream to the regular expression r and returns the corresponding string value.