package ecaml

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

A "regular expression", or "regexp" for short, is a pattern that denotes a (possibly infinite) set of strings.

(Info-goto-node "(elisp)Regular Expressions")

type t

type t is lazy. Construction functions (of_rx, quote, ...) don't construct the Emacs regexp until it is needed. Idiomatic use of a Regexp.t looks like:

let some_function =
  let regexp = Regexp.of_rx ... in
  fun a b c ->
    ... Regexp.match_ regexp ...

This idiom only constructs the Emacs regexp when it is needed, and avoids reconstructing it every time it is used.

val sexp_of_t : t -> Sexplib0.Sexp.t
val of_value_exn : Ecaml_value.Value.t -> t
val to_value : t -> Ecaml_value.Value.t
val of_rx : Rx.t -> t

Rx.t is the preferred way to construct regexps, especially when the alternative involves string manipulation in OCaml. of_rx is lazy, and doesn't construct the Emacs regexp until it is needed.

val match_anything : t
val match_nothing : t
val of_pattern : string -> t

(Info-goto-node "(elisp)Syntax of Regexps").

val to_pattern : t -> string
val any : t list -> t

any is lazy, and doesn't construct the Emacs regexp until it is needed.

val any_pattern : string list -> t

any_pattern is lazy, and doesn't construct the Emacs regexp until it is needed.

val quote : string -> t

quote string matches string and nothing else. quote is lazy, and doesn't construct the Emacs regexp until it is needed. (describe-function 'regexp-quote) (Info-goto-node "(elisp)Regexp Functions")

val any_quote : string list -> t

any_quote strings matches every string in strings, and nothing else. any_quote is lazy, and doesn't construct the Emacs regexp until it is needed. (describe-function 'regexp-opt) (Info-goto-node "(elisp)Regexp Functions")

module Last_match : sig ... end

Supplying ~update_last_match:true to a searching function causes Emacs to keep track of the "last match", i.e. the start and end positions of the segments of text found during the search. One can access parts of the last match via the Last_match functions. subexp is one based. (Info-goto-node "(elisp)Match Data")

val match_ : ?start:int -> ?update_last_match:bool -> t -> Text.t -> int option

match_ t text finds the first match of t in text, returns the index of the start of the match. (describe-function 'string-match) (describe-function 'string-match-p) (Info-goto-node "(elisp)Regexp Search")

val does_match : ?start:int -> ?update_last_match:bool -> t -> Text.t -> bool

does_match t text is is_some (match_ t text)

val extract : ?start:int -> ?subexp:int -> t -> Text.t -> string option
val extract_string : ?start:int -> ?subexp:int -> t -> string -> string option
val replace : t -> with_:Text.t -> in_:Text.t -> Text.t

(describe-function 'replace-regexp-in-string)

val replace_string : t -> with_:string -> in_:string -> string
val save_match_data : (_, 'a) Sync_or_async.t -> (unit -> 'a) -> 'a

(describe-function 'save-match-data)

OCaml

Innovation. Community. Security.