1
(* $Id: netstring_pcre.mli 800 2004-07-09 00:17:47Z stolpmann $ *)
3
(** Wrapper for regexps with PCRE syntax
5
* This module is a version of [Str] with a thread-safe interface,
6
* implemented using Pcre.
8
* This modules processes PCRE-style regular expressions. If you like
9
* to write [Str]-like regexps, you can also use {!Netstring_str} with
10
* almost the same signature.
13
(** Supported regexp syntax: See pcrepattern(3). *)
15
type regexp = Pcre.regexp;;
16
(** The type of regular expressions; now based on [Pcre] *)
18
type split_result = Pcre.split_result =
21
| Group of int * string
23
(** Here we keep compatiblity with [Pcre] *)
27
(** The type of matching results *)
29
val regexp: string -> regexp
30
(** Parses a regexp *)
31
val regexp_case_fold: string -> regexp
32
(** Parses a case-insensitive regexp *)
33
val quote: string -> string
34
(** Quotes a string such that it can be included in a regexp *)
35
val regexp_string: string -> regexp
36
(** Returns a regexp that matches exactly the string *)
37
val regexp_string_case_fold: string -> regexp
38
(** Returns a case-insensitive regexp that matches exactly the string *)
40
(** Note: the [groups] argument is ignored in the following functions.
41
* Once upon a time this argument determined how many groups were
42
* copied to the [result] value.
43
* Now all groups are accessible in the [result] value, no matter
48
?groups:int -> regexp -> string -> int -> result option
49
(** Matches the string at the position with the regexp. Returns
50
* [None] if no match is found. Returns [Some r] on success,
51
* and [r] describes the match.
55
?groups:int -> regexp -> string -> int -> (int * result)
56
(** Searches a match of the string with the regexp, starting at
57
* the position and in forward direction.
58
* Raises [Not_found] if no match could be found.
59
* Returns [(p,r)] when a match at position [p] is found,
64
?groups:int -> regexp -> string -> int -> (int * result)
65
(** Searches a match of the string with the regexp, starting at
66
* the position and in backward direction.
67
* Raises [Not_found] if no match could be found.
68
* Returns [(p,r)] when a match at position [p] is found,
73
string_partial_match: not available
76
(* The ~groups option is ignored *)
78
val matched_string : result -> string -> string
79
(** Extracts the matched part from the string. The string argument
80
* must be the same string passed to [string_match] or the search
81
* functions, and the result argument must be the corresponding
85
val match_beginning : result -> int
86
(** Returns the position where the matched part begins *)
88
val match_end : result -> int
89
(** Returns the position where the matched part ends *)
91
val matched_group : result -> int -> string -> string
92
(** Extracts the substring the nth group matches from the whole
93
* string. The string argument
94
* must be the same string passed to [string_match] or the search
95
* functions, and the result argument must be the corresponding
99
val group_beginning : result -> int -> int
100
(** Returns the position where the substring matching the nth
104
val group_end : result -> int -> int
105
(** Returns the position where the substring matching the nth
110
val global_replace: regexp -> string -> string -> string
111
(** [global_replace re templ s]: Replaces all matchings of [re] in
114
* In [templ] one can refer to matched groups by the backslash notation:
115
* [\1] refers to the first group, [\2] to the second etc.
116
* [\0] is the whole match. [\\ ] is the backslash character.
119
val replace_first: regexp -> string -> string -> string
120
(** [replace_first re templ s]: Replaces the first match of [re] in
123
* In [templ] one can refer to matched groups by the backslash notation:
124
* [\1] refers to the first group, [\2] to the second etc.
125
* [\0] is the whole match. [\\ ] is the backslash character.
128
val global_substitute:
130
regexp -> (result -> string -> string) -> string -> string
131
(** [global_substitute re subst s]: Applies the substitution function
132
* [subst] to all matchings of [re] in [s], and returns the
133
* transformed string. [subst] is called with the current [result]
134
* of the match and the whole string [s].
137
val substitute_first:
139
regexp -> (result -> string -> string) -> string -> string
140
(** [substitute_first re subst s]: Applies the substitution function
141
* [subst] to the first matching of [re] in [s], and returns the
142
* transformed string. [subst] is called with the current [result]
143
* of the match and the whole string [s].
147
(* replace_matched: not available *)
149
val split: regexp -> string -> string list
150
(** Splits the string according to the regexp in substrings.
151
* Occurrences of the delimiter at the beginning and the end
155
val bounded_split: regexp -> string -> int -> string list
156
(** Splits into at most [n] substrings, based on [split] *)
157
val split_delim: regexp -> string -> string list
158
(** Same as [split], but occurrences of the delimiter at the beginning
159
* and the end are returned as empty strings
161
val bounded_split_delim: regexp -> string -> int -> string list
162
(** Splits into at most [n] substrings, based on [split_delim] *)
163
val full_split: regexp -> string -> split_result list
164
(** Like [split_delim], but returns the delimiters in the result *)
165
val bounded_full_split: regexp -> string -> int -> split_result list
166
(** Splits into at most [n] substrings, based on [full_split] *)
168
val string_before: string -> int -> string
169
(** The first [n] characters of a string *)
170
val string_after: string -> int -> string
171
(** The last [n] characters of a string *)
172
val first_chars: string -> int -> string
173
(** Same as [string_before] *)
174
val last_chars: string -> int -> string
175
(** Same as [string_after] *)