Page
Library
Module
Module type
Parameter
Class
Class type
Source
Lua_patternImplementation of Lua patterns. Patterns are a simplified regex meant to be easier to implement and use.
module Capture : sig ... endCaptures are ranges that have been matched in the search string.
module Match : sig ... endMatches that the pattern has matched into the search strings.
val of_string : string -> t optionCompile a pattern.
val find : ?start:int -> string -> t -> (int * int) optionFind 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 -> stringHelper 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"