File: Str.html

package info (click to toggle)
ocaml-doc 4.11-2
  • links: PTS, VCS
  • area: non-free
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 20,580 kB
  • sloc: sh: 37; makefile: 11
file content (481 lines) | stat: -rw-r--r-- 31,986 bytes parent folder | download
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="style.css" type="text/css">
<meta content="text/html; charset=iso-8859-1" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="Start" href="index.html">
<link rel="previous" href="Stdlib.html">
<link rel="next" href="Stream.html">
<link rel="Up" href="index.html">
<link title="Index of types" rel=Appendix href="index_types.html">
<link title="Index of extensions" rel=Appendix href="index_extensions.html">
<link title="Index of exceptions" rel=Appendix href="index_exceptions.html">
<link title="Index of values" rel=Appendix href="index_values.html">
<link title="Index of modules" rel=Appendix href="index_modules.html">
<link title="Index of module types" rel=Appendix href="index_module_types.html">
<link title="Arg" rel="Chapter" href="Arg.html">
<link title="Array" rel="Chapter" href="Array.html">
<link title="ArrayLabels" rel="Chapter" href="ArrayLabels.html">
<link title="Bigarray" rel="Chapter" href="Bigarray.html">
<link title="Bool" rel="Chapter" href="Bool.html">
<link title="Buffer" rel="Chapter" href="Buffer.html">
<link title="Bytes" rel="Chapter" href="Bytes.html">
<link title="BytesLabels" rel="Chapter" href="BytesLabels.html">
<link title="Callback" rel="Chapter" href="Callback.html">
<link title="CamlinternalFormat" rel="Chapter" href="CamlinternalFormat.html">
<link title="CamlinternalFormatBasics" rel="Chapter" href="CamlinternalFormatBasics.html">
<link title="CamlinternalLazy" rel="Chapter" href="CamlinternalLazy.html">
<link title="CamlinternalMod" rel="Chapter" href="CamlinternalMod.html">
<link title="CamlinternalOO" rel="Chapter" href="CamlinternalOO.html">
<link title="Char" rel="Chapter" href="Char.html">
<link title="Complex" rel="Chapter" href="Complex.html">
<link title="Condition" rel="Chapter" href="Condition.html">
<link title="Digest" rel="Chapter" href="Digest.html">
<link title="Dynlink" rel="Chapter" href="Dynlink.html">
<link title="Ephemeron" rel="Chapter" href="Ephemeron.html">
<link title="Event" rel="Chapter" href="Event.html">
<link title="Filename" rel="Chapter" href="Filename.html">
<link title="Float" rel="Chapter" href="Float.html">
<link title="Format" rel="Chapter" href="Format.html">
<link title="Fun" rel="Chapter" href="Fun.html">
<link title="Gc" rel="Chapter" href="Gc.html">
<link title="Genlex" rel="Chapter" href="Genlex.html">
<link title="Hashtbl" rel="Chapter" href="Hashtbl.html">
<link title="Int" rel="Chapter" href="Int.html">
<link title="Int32" rel="Chapter" href="Int32.html">
<link title="Int64" rel="Chapter" href="Int64.html">
<link title="Lazy" rel="Chapter" href="Lazy.html">
<link title="Lexing" rel="Chapter" href="Lexing.html">
<link title="List" rel="Chapter" href="List.html">
<link title="ListLabels" rel="Chapter" href="ListLabels.html">
<link title="Map" rel="Chapter" href="Map.html">
<link title="Marshal" rel="Chapter" href="Marshal.html">
<link title="MoreLabels" rel="Chapter" href="MoreLabels.html">
<link title="Mutex" rel="Chapter" href="Mutex.html">
<link title="Nativeint" rel="Chapter" href="Nativeint.html">
<link title="Obj" rel="Chapter" href="Obj.html">
<link title="Ocaml_operators" rel="Chapter" href="Ocaml_operators.html">
<link title="Oo" rel="Chapter" href="Oo.html">
<link title="Option" rel="Chapter" href="Option.html">
<link title="Parsing" rel="Chapter" href="Parsing.html">
<link title="Printexc" rel="Chapter" href="Printexc.html">
<link title="Printf" rel="Chapter" href="Printf.html">
<link title="Queue" rel="Chapter" href="Queue.html">
<link title="Random" rel="Chapter" href="Random.html">
<link title="Result" rel="Chapter" href="Result.html">
<link title="Scanf" rel="Chapter" href="Scanf.html">
<link title="Seq" rel="Chapter" href="Seq.html">
<link title="Set" rel="Chapter" href="Set.html">
<link title="Spacetime" rel="Chapter" href="Spacetime.html">
<link title="Stack" rel="Chapter" href="Stack.html">
<link title="StdLabels" rel="Chapter" href="StdLabels.html">
<link title="Stdlib" rel="Chapter" href="Stdlib.html">
<link title="Str" rel="Chapter" href="Str.html">
<link title="Stream" rel="Chapter" href="Stream.html">
<link title="String" rel="Chapter" href="String.html">
<link title="StringLabels" rel="Chapter" href="StringLabels.html">
<link title="Sys" rel="Chapter" href="Sys.html">
<link title="Thread" rel="Chapter" href="Thread.html">
<link title="ThreadUnix" rel="Chapter" href="ThreadUnix.html">
<link title="Uchar" rel="Chapter" href="Uchar.html">
<link title="Unit" rel="Chapter" href="Unit.html">
<link title="Unix" rel="Chapter" href="Unix.html">
<link title="UnixLabels" rel="Chapter" href="UnixLabels.html">
<link title="Weak" rel="Chapter" href="Weak.html"><link title="Regular expressions" rel="Section" href="#1_Regularexpressions">
<link title="String matching and searching" rel="Section" href="#1_Stringmatchingandsearching">
<link title="Replacement" rel="Section" href="#1_Replacement">
<link title="Splitting" rel="Section" href="#1_Splitting">
<link title="Extracting substrings" rel="Section" href="#1_Extractingsubstrings">
<title>Str</title>
</head>
<body>
<div class="navbar"><a class="pre" href="Stdlib.html" title="Stdlib">Previous</a>
&nbsp;<a class="up" href="index.html" title="Index">Up</a>
&nbsp;<a class="post" href="Stream.html" title="Stream">Next</a>
</div>
<h1>Module <a href="type_Str.html">Str</a></h1>

<pre><span id="MODULEStr"><span class="keyword">module</span> Str</span>: <code class="code"><span class="keyword">sig</span></code> <a href="Str.html">..</a> <code class="code"><span class="keyword">end</span></code></pre><div class="info module top">
<div class="info-desc">
<p>Regular expressions and high-level string processing</p>
</div>
</div>
<hr width="100%">
<h2 id="1_Regularexpressions">Regular expressions</h2>
<pre><span id="TYPEregexp"><span class="keyword">type</span> <code class="type"></code>regexp</span> </pre>
<div class="info ">
<div class="info-desc">
<p>The type of compiled regular expressions.</p>
</div>
</div>


<pre><span id="VALregexp"><span class="keyword">val</span> regexp</span> : <code class="type">string -> <a href="Str.html#TYPEregexp">regexp</a></code></pre><div class="info ">
<div class="info-desc">
<p>Compile a regular expression. The following constructs are
    recognized:</p>
<ul>
<li><code class="code">.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code> Matches any character except newline.</li>
<li><code class="code">*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code> (postfix) Matches the preceding expression zero, one or
              several times</li>
<li><code class="code">+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code> (postfix) Matches the preceding expression one or
              several times</li>
<li><code class="code">?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code> (postfix) Matches the preceding expression once or
              not at all</li>
<li><code class="code">[..]&nbsp;&nbsp;</code> Character set. Ranges are denoted with <code class="code">-</code>, as in <code class="code">[a-z]</code>.
              An initial <code class="code">^</code>, as in <code class="code">[^0-9]</code>, complements the set.
              To include a <code class="code">]</code> character in a set, make it the first
              character of the set. To include a <code class="code">-</code> character in a set,
              make it the first or the last character of the set.</li>
<li><code class="code">^&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code> Matches at beginning of line: either at the beginning of
              the matched string, or just after a '\n' character.</li>
<li><code class="code">$&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code> Matches at end of line: either at the end of the matched
              string, or just before a '\n' character.</li>
<li><code class="code">\|    </code> (infix) Alternative between two expressions.</li>
<li><code class="code">\(..\)</code> Grouping and naming of the enclosed expression.</li>
<li><code class="code">\1    </code> The text matched by the first <code class="code">\(...\)</code> expression
     (<code class="code">\2</code> for the second expression, and so on up to <code class="code">\9</code>).</li>
<li><code class="code">\b    </code> Matches word boundaries.</li>
<li><code class="code">\     </code> Quotes special characters.  The special characters
              are <code class="code">$^\.*+?[]</code>.</li>
</ul>
<p>Note: the argument to <code class="code">regexp</code> is usually a string literal. In this
   case, any backslash character in the regular expression must be
   doubled to make it past the OCaml string parser. For example, the
   following expression:</p>
<pre class="codepre"><code class="code"> <span class="keyword">let</span> r = <span class="constructor">Str</span>.regexp <span class="string">"hello \\([A-Za-z]+\\)"</span> <span class="keyword">in</span>
      <span class="constructor">Str</span>.replace_first r <span class="string">"\\1"</span> <span class="string">"hello world"</span> </code></pre><p>returns the string <code class="code"><span class="string">"world"</span></code>.</p>

<p>In particular, if you want a regular expression that matches a single
   backslash character, you need to quote it in the argument to <code class="code">regexp</code>
   (according to the last item of the list above) by adding a second
   backslash. Then you need to quote both backslashes (according to the
   syntax of string constants in OCaml) by doubling them again, so you
   need to write four backslash characters: <code class="code"><span class="constructor">Str</span>.regexp&nbsp;<span class="string">"\\\\"</span></code>.</p>
</div>
</div>

<pre><span id="VALregexp_case_fold"><span class="keyword">val</span> regexp_case_fold</span> : <code class="type">string -> <a href="Str.html#TYPEregexp">regexp</a></code></pre><div class="info ">
<div class="info-desc">
<p>Same as <code class="code">regexp</code>, but the compiled expression will match text
    in a case-insensitive way: uppercase and lowercase letters will
    be considered equivalent.</p>
</div>
</div>

<pre><span id="VALquote"><span class="keyword">val</span> quote</span> : <code class="type">string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Str</span>.quote&nbsp;s</code> returns a regexp string that matches exactly
   <code class="code">s</code> and nothing else.</p>
</div>
</div>

<pre><span id="VALregexp_string"><span class="keyword">val</span> regexp_string</span> : <code class="type">string -> <a href="Str.html#TYPEregexp">regexp</a></code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Str</span>.regexp_string&nbsp;s</code> returns a regular expression
   that matches exactly <code class="code">s</code> and nothing else.</p>
</div>
</div>

<pre><span id="VALregexp_string_case_fold"><span class="keyword">val</span> regexp_string_case_fold</span> : <code class="type">string -> <a href="Str.html#TYPEregexp">regexp</a></code></pre><div class="info ">
<div class="info-desc">
<p><code class="code"><span class="constructor">Str</span>.regexp_string_case_fold</code> is similar to <a href="Str.html#VALregexp_string"><code class="code"><span class="constructor">Str</span>.regexp_string</code></a>,
   but the regexp matches in a case-insensitive way.</p>
</div>
</div>
<h2 id="1_Stringmatchingandsearching">String matching and searching</h2>
<pre><span id="VALstring_match"><span class="keyword">val</span> string_match</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> int -> bool</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">string_match&nbsp;r&nbsp;s&nbsp;start</code> tests whether a substring of <code class="code">s</code> that
   starts at position <code class="code">start</code> matches the regular expression <code class="code">r</code>.
   The first character of a string has position <code class="code">0</code>, as usual.</p>
</div>
</div>

<pre><span id="VALsearch_forward"><span class="keyword">val</span> search_forward</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> int -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">search_forward&nbsp;r&nbsp;s&nbsp;start</code> searches the string <code class="code">s</code> for a substring
   matching the regular expression <code class="code">r</code>. The search starts at position
   <code class="code">start</code> and proceeds towards the end of the string.
   Return the position of the first character of the matched
   substring.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Not_found</code> if no substring matches.</li>
</ul>
</div>

<pre><span id="VALsearch_backward"><span class="keyword">val</span> search_backward</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> int -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">search_backward&nbsp;r&nbsp;s&nbsp;last</code> searches the string <code class="code">s</code> for a
  substring matching the regular expression <code class="code">r</code>. The search first
  considers substrings that start at position <code class="code">last</code> and proceeds
  towards the beginning of string. Return the position of the first
  character of the matched substring.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Not_found</code> if no substring matches.</li>
</ul>
</div>

<pre><span id="VALstring_partial_match"><span class="keyword">val</span> string_partial_match</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> int -> bool</code></pre><div class="info ">
<div class="info-desc">
<p>Similar to <a href="Str.html#VALstring_match"><code class="code"><span class="constructor">Str</span>.string_match</code></a>, but also returns true if
   the argument string is a prefix of a string that matches.
   This includes the case of a true complete match.</p>
</div>
</div>

<pre><span id="VALmatched_string"><span class="keyword">val</span> matched_string</span> : <code class="type">string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">matched_string&nbsp;s</code> returns the substring of <code class="code">s</code> that was matched
   by the last call to one of the following matching or searching
   functions:</p>
<ul>
<li><a href="Str.html#VALstring_match"><code class="code"><span class="constructor">Str</span>.string_match</code></a></li>
<li><a href="Str.html#VALsearch_forward"><code class="code"><span class="constructor">Str</span>.search_forward</code></a></li>
<li><a href="Str.html#VALsearch_backward"><code class="code"><span class="constructor">Str</span>.search_backward</code></a></li>
<li><a href="Str.html#VALstring_partial_match"><code class="code"><span class="constructor">Str</span>.string_partial_match</code></a></li>
<li><a href="Str.html#VALglobal_substitute"><code class="code"><span class="constructor">Str</span>.global_substitute</code></a></li>
<li><a href="Str.html#VALsubstitute_first"><code class="code"><span class="constructor">Str</span>.substitute_first</code></a></li>
</ul>
<p>provided that none of the following functions was called in between:</p>
<ul>
<li><a href="Str.html#VALglobal_replace"><code class="code"><span class="constructor">Str</span>.global_replace</code></a></li>
<li><a href="Str.html#VALreplace_first"><code class="code"><span class="constructor">Str</span>.replace_first</code></a></li>
<li><a href="Str.html#VALsplit"><code class="code"><span class="constructor">Str</span>.split</code></a></li>
<li><a href="Str.html#VALbounded_split"><code class="code"><span class="constructor">Str</span>.bounded_split</code></a></li>
<li><a href="Str.html#VALsplit_delim"><code class="code"><span class="constructor">Str</span>.split_delim</code></a></li>
<li><a href="Str.html#VALbounded_split_delim"><code class="code"><span class="constructor">Str</span>.bounded_split_delim</code></a></li>
<li><a href="Str.html#VALfull_split"><code class="code"><span class="constructor">Str</span>.full_split</code></a></li>
<li><a href="Str.html#VALbounded_full_split"><code class="code"><span class="constructor">Str</span>.bounded_full_split</code></a></li>
</ul>
<p>Note: in the case of <code class="code">global_substitute</code> and <code class="code">substitute_first</code>,
   a call to <code class="code">matched_string</code> is only valid within the <code class="code">subst</code> argument,
   not after <code class="code">global_substitute</code> or <code class="code">substitute_first</code> returns.</p>

<p>The user must make sure that the parameter <code class="code">s</code> is the same string
   that was passed to the matching or searching function.</p>
</div>
</div>

<pre><span id="VALmatch_beginning"><span class="keyword">val</span> match_beginning</span> : <code class="type">unit -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">match_beginning()</code> returns the position of the first character
   of the substring that was matched by the last call to a matching
   or searching function (see <a href="Str.html#VALmatched_string"><code class="code"><span class="constructor">Str</span>.matched_string</code></a> for details).</p>
</div>
</div>

<pre><span id="VALmatch_end"><span class="keyword">val</span> match_end</span> : <code class="type">unit -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">match_end()</code> returns the position of the character following the
   last character of the substring that was matched by the last call
   to a matching or searching function (see <a href="Str.html#VALmatched_string"><code class="code"><span class="constructor">Str</span>.matched_string</code></a> for
   details).</p>
</div>
</div>

<pre><span id="VALmatched_group"><span class="keyword">val</span> matched_group</span> : <code class="type">int -> string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">matched_group&nbsp;n&nbsp;s</code> returns the substring of <code class="code">s</code> that was matched
   by the <code class="code">n</code>th group <code class="code">\(...\)</code> of the regular expression that was
   matched by the last call to a matching or searching function (see
   <a href="Str.html#VALmatched_string"><code class="code"><span class="constructor">Str</span>.matched_string</code></a> for details).
   The user must make sure that the parameter <code class="code">s</code> is the same string
   that was passed to the matching or searching function.</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b> <code>Not_found</code> if the <code class="code">n</code>th group
   of the regular expression was not matched.  This can happen
   with groups inside alternatives <code class="code">\|</code>, options <code class="code">?</code>
   or repetitions <code class="code">*</code>.  For instance, the empty string will match
   <code class="code">\(a\)*</code>, but <code class="code">matched_group&nbsp;1&nbsp;<span class="string">""</span></code> will raise <code class="code"><span class="constructor">Not_found</span></code>
   because the first group itself was not matched.</li>
</ul>
</div>

<pre><span id="VALgroup_beginning"><span class="keyword">val</span> group_beginning</span> : <code class="type">int -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">group_beginning&nbsp;n</code> returns the position of the first character
   of the substring that was matched by the <code class="code">n</code>th group of
   the regular expression that was matched by the last call to a
   matching or searching function (see <a href="Str.html#VALmatched_string"><code class="code"><span class="constructor">Str</span>.matched_string</code></a> for details).</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b><ul><li><code>Not_found</code> if the <code class="code">n</code>th group of the regular expression
   was not matched.</li>
<li><code>Invalid_argument</code> if there are fewer than <code class="code">n</code> groups in
   the regular expression.</li>
</ul></li>
</ul>
</div>

<pre><span id="VALgroup_end"><span class="keyword">val</span> group_end</span> : <code class="type">int -> int</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">group_end&nbsp;n</code> returns
   the position of the character following the last character of
   substring that was matched by the <code class="code">n</code>th group of the regular
   expression that was matched by the last call to a matching or
   searching function (see <a href="Str.html#VALmatched_string"><code class="code"><span class="constructor">Str</span>.matched_string</code></a> for details).</p>
</div>
<ul class="info-attributes">
<li><b>Raises</b><ul><li><code>Not_found</code> if the <code class="code">n</code>th group of the regular expression
   was not matched.</li>
<li><code>Invalid_argument</code> if there are fewer than <code class="code">n</code> groups in
   the regular expression.</li>
</ul></li>
</ul>
</div>
<h2 id="1_Replacement">Replacement</h2>
<pre><span id="VALglobal_replace"><span class="keyword">val</span> global_replace</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">global_replace&nbsp;regexp&nbsp;templ&nbsp;s</code> returns a string identical to <code class="code">s</code>,
   except that all substrings of <code class="code">s</code> that match <code class="code">regexp</code> have been
   replaced by <code class="code">templ</code>. The replacement template <code class="code">templ</code> can contain
   <code class="code">\1</code>, <code class="code">\2</code>, etc; these sequences will be replaced by the text
   matched by the corresponding group in the regular expression.
   <code class="code">\0</code> stands for the text matched by the whole regular expression.</p>
</div>
</div>

<pre><span id="VALreplace_first"><span class="keyword">val</span> replace_first</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> string -> string</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="Str.html#VALglobal_replace"><code class="code"><span class="constructor">Str</span>.global_replace</code></a>, except that only the first substring
   matching the regular expression is replaced.</p>
</div>
</div>

<pre><span id="VALglobal_substitute"><span class="keyword">val</span> global_substitute</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> (string -> string) -> string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">global_substitute&nbsp;regexp&nbsp;subst&nbsp;s</code> returns a string identical
   to <code class="code">s</code>, except that all substrings of <code class="code">s</code> that match <code class="code">regexp</code>
   have been replaced by the result of function <code class="code">subst</code>. The
   function <code class="code">subst</code> is called once for each matching substring,
   and receives <code class="code">s</code> (the whole text) as argument.</p>
</div>
</div>

<pre><span id="VALsubstitute_first"><span class="keyword">val</span> substitute_first</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> (string -> string) -> string -> string</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="Str.html#VALglobal_substitute"><code class="code"><span class="constructor">Str</span>.global_substitute</code></a>, except that only the first substring
   matching the regular expression is replaced.</p>
</div>
</div>

<pre><span id="VALreplace_matched"><span class="keyword">val</span> replace_matched</span> : <code class="type">string -> string -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">replace_matched&nbsp;repl&nbsp;s</code> returns the replacement text <code class="code">repl</code>
   in which <code class="code">\1</code>, <code class="code">\2</code>, etc. have been replaced by the text
   matched by the corresponding groups in the regular expression
   that was matched by the last call to a matching or searching
   function (see <a href="Str.html#VALmatched_string"><code class="code"><span class="constructor">Str</span>.matched_string</code></a> for details).
   <code class="code">s</code> must be the same string that was passed to the matching or
   searching function.</p>
</div>
</div>
<h2 id="1_Splitting">Splitting</h2>
<pre><span id="VALsplit"><span class="keyword">val</span> split</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> string list</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">split&nbsp;r&nbsp;s</code> splits <code class="code">s</code> into substrings, taking as delimiters
   the substrings that match <code class="code">r</code>, and returns the list of substrings.
   For instance, <code class="code">split&nbsp;(regexp&nbsp;<span class="string">"[&nbsp;\t]+"</span>)&nbsp;s</code> splits <code class="code">s</code> into
   blank-separated words.  An occurrence of the delimiter at the
   beginning or at the end of the string is ignored.</p>
</div>
</div>

<pre><span id="VALbounded_split"><span class="keyword">val</span> bounded_split</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> int -> string list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="Str.html#VALsplit"><code class="code"><span class="constructor">Str</span>.split</code></a>, but splits into at most <code class="code">n</code> substrings,
   where <code class="code">n</code> is the extra integer parameter.</p>
</div>
</div>

<pre><span id="VALsplit_delim"><span class="keyword">val</span> split_delim</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> string list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="Str.html#VALsplit"><code class="code"><span class="constructor">Str</span>.split</code></a> but occurrences of the
   delimiter at the beginning and at the end of the string are
   recognized and returned as empty strings in the result.
   For instance, <code class="code">split_delim&nbsp;(regexp&nbsp;<span class="string">"&nbsp;"</span>)&nbsp;<span class="string">"&nbsp;abc&nbsp;"</span></code>
   returns <code class="code">[<span class="string">""</span>;&nbsp;<span class="string">"abc"</span>;&nbsp;<span class="string">""</span>]</code>, while <code class="code">split</code> with the same
   arguments returns <code class="code">[<span class="string">"abc"</span>]</code>.</p>
</div>
</div>

<pre><span id="VALbounded_split_delim"><span class="keyword">val</span> bounded_split_delim</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> int -> string list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="Str.html#VALbounded_split"><code class="code"><span class="constructor">Str</span>.bounded_split</code></a>, but occurrences of the
   delimiter at the beginning and at the end of the string are
   recognized and returned as empty strings in the result.</p>
</div>
</div>

<pre><code><span id="TYPEsplit_result"><span class="keyword">type</span> <code class="type"></code>split_result</span> = </code></pre><table class="typetable">
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTsplit_result.Text"><span class="constructor">Text</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>

</tr>
<tr>
<td align="left" valign="top" >
<code><span class="keyword">|</span></code></td>
<td align="left" valign="top" >
<code><span id="TYPEELTsplit_result.Delim"><span class="constructor">Delim</span></span> <span class="keyword">of</span> <code class="type">string</code></code></td>

</tr></table>



<pre><span id="VALfull_split"><span class="keyword">val</span> full_split</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> <a href="Str.html#TYPEsplit_result">split_result</a> list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="Str.html#VALsplit_delim"><code class="code"><span class="constructor">Str</span>.split_delim</code></a>, but returns
   the delimiters as well as the substrings contained between
   delimiters.  The former are tagged <code class="code"><span class="constructor">Delim</span></code> in the result list;
   the latter are tagged <code class="code"><span class="constructor">Text</span></code>.  For instance,
   <code class="code">full_split&nbsp;(regexp&nbsp;<span class="string">"[{}]"</span>)&nbsp;<span class="string">"{ab}"</span></code> returns
   <code class="code">[<span class="constructor">Delim</span>&nbsp;<span class="string">"{"</span>;&nbsp;<span class="constructor">Text</span>&nbsp;<span class="string">"ab"</span>;&nbsp;<span class="constructor">Delim</span>&nbsp;<span class="string">"}"</span>]</code>.</p>
</div>
</div>

<pre><span id="VALbounded_full_split"><span class="keyword">val</span> bounded_full_split</span> : <code class="type"><a href="Str.html#TYPEregexp">regexp</a> -> string -> int -> <a href="Str.html#TYPEsplit_result">split_result</a> list</code></pre><div class="info ">
<div class="info-desc">
<p>Same as <a href="Str.html#VALbounded_split_delim"><code class="code"><span class="constructor">Str</span>.bounded_split_delim</code></a>, but returns
   the delimiters as well as the substrings contained between
   delimiters.  The former are tagged <code class="code"><span class="constructor">Delim</span></code> in the result list;
   the latter are tagged <code class="code"><span class="constructor">Text</span></code>.</p>
</div>
</div>
<h2 id="1_Extractingsubstrings">Extracting substrings</h2>
<pre><span id="VALstring_before"><span class="keyword">val</span> string_before</span> : <code class="type">string -> int -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">string_before&nbsp;s&nbsp;n</code> returns the substring of all characters of <code class="code">s</code>
   that precede position <code class="code">n</code> (excluding the character at
   position <code class="code">n</code>).</p>
</div>
</div>

<pre><span id="VALstring_after"><span class="keyword">val</span> string_after</span> : <code class="type">string -> int -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">string_after&nbsp;s&nbsp;n</code> returns the substring of all characters of <code class="code">s</code>
   that follow position <code class="code">n</code> (including the character at
   position <code class="code">n</code>).</p>
</div>
</div>

<pre><span id="VALfirst_chars"><span class="keyword">val</span> first_chars</span> : <code class="type">string -> int -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">first_chars&nbsp;s&nbsp;n</code> returns the first <code class="code">n</code> characters of <code class="code">s</code>.
   This is the same function as <a href="Str.html#VALstring_before"><code class="code"><span class="constructor">Str</span>.string_before</code></a>.</p>
</div>
</div>

<pre><span id="VALlast_chars"><span class="keyword">val</span> last_chars</span> : <code class="type">string -> int -> string</code></pre><div class="info ">
<div class="info-desc">
<p><code class="code">last_chars&nbsp;s&nbsp;n</code> returns the last <code class="code">n</code> characters of <code class="code">s</code>.</p>
</div>
</div>
</body></html>