File: regexp.mli

package info (click to toggle)
js-of-ocaml 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 7,372 kB
  • sloc: ml: 70,468; javascript: 8,238; ansic: 319; makefile: 217; lisp: 23; sh: 6; perl: 4
file content (94 lines) | stat: -rw-r--r-- 3,580 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
(* Js_of_ocaml library
 * http://www.ocsigen.org/js_of_ocaml/
 * Copyright (C) 2010 Raphaël Proust, Jérôme Vouillon
 * Laboratoire PPS - CNRS Université Paris Diderot
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, with linking exception;
 * either version 2.1 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *)

(** Types for regexps. *)

(** {i Warning:} the regexp syntax is the javascript one. It differs
    from the syntax used by the [Str] module from the OCaml standard
    library.

    @see <https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp#section_5> Regexp object on Mozilla Developer Network.

 *)

type regexp
(** The type for regexps. *)

type result
(** The type for match result. *)

(** Constructors *)

val regexp : string -> regexp
(** Simple regexp constructor. *)

val regexp_case_fold : string -> regexp
(** Same as [regexp] but matching will be performed in a case
    insensitive way. *)

val regexp_with_flag : string -> string -> regexp
(** Regexp constructor with flag that allow for case-insensitive search
    or multiline search (the global flag is always set). *)

val quote : string -> string
(** Escapes characters with special meaning in the regexp context. *)

val regexp_string : string -> regexp
(** [regexp_string s] creates a regexp matching the exact string [s]. *)

val regexp_string_case_fold : string -> regexp
(** Same as [regexp_string] but matching will be performed in a case
    insensitive way. *)

(** Functions *)

val string_match : regexp -> string -> int -> result option
(** [string_match r s i] matches the string [s] starting from the [i]th
    character. Evaluates to [None] if [s] (from the [i]th character) doesn't
    match [r]. *)

val search : regexp -> string -> int -> (int * result) option
(** [search r s i] evaluates to the index of the match and the match result or
    [None] if [s] (starting from [i]) doesn't match [r]. *)

val search_forward : regexp -> string -> int -> (int * result) option
(** Same as [search]. *)

val matched_string : result -> string
(** [matched_string r] return the exact substring that matched when evaluating
    [r]. *)

val matched_group : result -> int -> string option
(** [matched_group r i] is the [i]th group matched. Groups in matches are
  * obtained with parentheses. Groups are 1-based. *)

val global_replace : regexp -> string -> string -> string
(** [global_replace r s by] replaces all of the matches of [r] in [s] by [by]. *)

val replace_first : regexp -> string -> string -> string
(** [replace_first r s by] replaces the first match of [r] in [s] by [by]. *)

val split : regexp -> string -> string list
(** [split r s] splits the string [s] erasing matches with [r].
    [split (regexp " ") "toto tutu tata"] is [["toto";"tutu";"tata"]].*)

val bounded_split : regexp -> string -> int -> string list
(** [bounded_split r s i] is like [split r s] except that the result's length is
    less than [i]. *)