Up

Module Search_pattern

Substring search and replace functions. They use the Knuth-Morris-Pratt algorithm (KMP) under the hood.

The functions in the Search_pattern module allow the program to preprocess the searched pattern once and then use it many times without further allocations.

Signature

type t
val sexp_of_t : t -> Sexplib.Sexp.t
val create : string -> t

create pattern preprocesses pattern as per KMP, building an int array of length length pattern. All inputs are valid.

val index : ?pos:int -> t -> in_:string -> int option

pos < 0 or pos >= length string result in no match (hence index returns None and index_exn raises).

val index_exn : ?pos:int -> t -> in_:string -> int
val index_all : t -> may_overlap:bool -> in_:string -> int list
ERROR: core_string.mli:106:7-106:8
5:7-5:8 :
text expected
val replace_first : ?pos:int -> t -> in_:string -> with_:string -> string

Note that the result of replace_all pattern ~in_:text ~with_:r may still contain pattern, e.g.


        replace_all (create "bc") ~in:"aabbcc" ~with_:"cb" = "aabcbc"
      
val replace_all : t -> in_:string -> with_:string -> string