Library
Module
Module type
Parameter
Class
Class type
Implementation of Lua patterns. Patterns are a simplified regex meant to be easier to implement and use.
module Capture : sig ... end
Captures are ranges that have been matched in the search string.
module Match : sig ... end
Matches that the pattern has matched into the search strings.
val of_string : string -> t option
Compile a pattern.
val find : ?start:int -> string -> t -> (int * int) option
Find the first successful pattern hit in the search string.
Replace a matches in a string. Replacing is a function on the Match.t
returning a new string.
val rep_str : string -> Match.t -> string
Helper function for the common case where substitute
is to replace a pattern with a static string. rep_str
also supports access captures with
%N
where
N
is a number from 1 to 9.
Example:
let pat = Option.value_exn (of_string "(%d+)(%a+)") in
substitute ~s:"123foobar" ~r:(rep_str "%2%1") pat
yields
Some "foobar123"