module Cf_regex:sig
..end
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:
`n
Matches LF ("newline") character.`t
Matches TAB character.`r
Matches RETURN character.`a
Matches an alphabetical character.`d
Matches a decimal digit character.`i
Matches an alphanumerical character.`s
Matches a TAB, LF, VT, FF, CR or SPACE (whitespace) character.`w
Matches a character other than a whitespace character.`xNN
Matches the character with hexadecimal code NN
.`DDD
Matches the character with decimal code DDD
, where DDD is a
three digit number between 000
and 255
.`c_
Matches the control character corresponding to the subsequent
printable character, e.g. `cA
is CONTROL-A, and `c[
is ESCAPE..
Matches any character except newline.*
(postfix) Matches the preceding expression, zero, one or
several times in sequence.+
(postfix) Matches the preceding expression, one or several
times in sequence.?
(postfix) Matches the preceding expression once or not at all.[..]
Character set. Ranges are denoted with '-'
, as in [a-z]
.
An initial '^'
, as in [^0-9]
, complements the set. Special
characters in the character set syntax may be included in the set by
escaping them with a backtick, e.g. [`^```]]
is a set containing
three characters: the carat, the backtick and the right bracket
characters.(..|..)
Alternatives. Matches one of the expressions between the
parentheses, which are separated by vertical bar characters.`_
Escaped special character. The special characters are '`'
,
'.'
, '*'
, '+'
, '?'
, '('
, '|'
, ')'
, '['
.module DFA:Cf_dfa.T
with type S.t = char
exception Error of string
type
t
val expr_parse : (char, DFA.x) Cf_parser.t
val expr_of_seq : char Cf_seq.t -> DFA.x
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
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
val unquote : (char, char) Cf_flow.t
val of_expression : DFA.x -> t
of_expression x
to produce a regular expression from the DFA
expression x
.val of_seq : char Cf_seq.t -> t
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
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
test r s
to test whether the string s
matches the regular
expression r
.val search : t -> char Cf_seq.t -> int * int
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
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
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
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
parse r
to produce a parser that matches the input stream to the
regular expression r
and returns the corresponding string value.