Module Cf_regx

Regular expression parsing, search and matching.

Overview

This module implements simple regular expression parsing, search and matching in pure Objective Caml for 8-bit extended ASCII text.

Use any of the following constructions in regular expressions:

Interface
module DFA : sig ... end

The deterministic finite automata on octet character symbols.

type t

The type of a compiled regular expression.

val of_string : string -> t

Use of_string s to make a regular expression denoted by s. Raises Invalid_argment if s does not denote a valid regular expression.

val of_chars : char Seq.t -> t

Use of_chars s to make a regular expression denoted by the characters in s. Raises Invalid_argment if the characters do not denote a valid regular expression.

val of_dfa_term : DFA.term -> t

Use of_dfa_term s to make a regular expression for recognizing the language term s.

val test : t -> string -> bool

Use test r s to test whether r recognizes s. Returns true if all the characters in s are not rejected and the DFA reaches at least one final state, otherwise returns false.

val contains : t -> string -> bool

Use contains r s to test whether r recognizes any substring of s.

Use search r s to search with r in a confluently persistent sequence s for the first accepted subsequence. Returns None if s does not contain a matching subsequence. Otherwise, returns Some (start, limit) where start is the index of the first matching subsequence, and limit is the index after the end of the longest matching subsequence.

val split : t -> string Cf_slice.t -> string Cf_slice.t Seq.t

Use split r s to split s into a sequence of slices comprising the substrings in s that are separated by disjoint substrings matching r, which are found by searching from left to right. If r does not match any substring in s, then a sequence containing just s is returned, even if s is an empty slice.

val quote : string -> string

Use quote s to make a copy of s by converting all the special characters into escape sequences.

val unquote : string -> string

Use unquote s to make a copy of s by converting all the escape sequences into ordinary characters.