<!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"> <link rel="Start" href="index.html"> <link rel="Up" href="index.html"> <link title="Index of types" rel=Appendix href="index_types.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="Pcre" rel="Chapter" href="Pcre.html"><link title="Exceptions" rel="Section" href="#6_Exceptions"> <link title="Compilation and runtime flags and their conversion functions" rel="Section" href="#6_Compilationandruntimeflagsandtheirconversionfunctions"> <link title="Information on the PCRE-configuration (build-time options)" rel="Section" href="#6_InformationonthePCREconfigurationbuildtimeoptions"> <link title="Information on patterns" rel="Section" href="#6_Informationonpatterns"> <link title="Compilation of patterns" rel="Section" href="#6_Compilationofpatterns"> <link title="Subpattern extraction" rel="Section" href="#6_Subpatternextraction"> <link title="Callouts" rel="Section" href="#6_Callouts"> <link title="Matching of patterns and subpattern extraction" rel="Section" href="#6_Matchingofpatternsandsubpatternextraction"> <link title="String substitution" rel="Section" href="#6_Stringsubstitution"> <link title="Splitting" rel="Section" href="#6_Splitting"> <link title="Additional convenience functions" rel="Section" href="#6_Additionalconveniencefunctions"> <link title="UNSAFE STUFF - USE WITH CAUTION!" rel="Section" href="#6_UNSAFESTUFFUSEWITHCAUTION"> <title>Pcre</title> </head> <body> <div class="navbar"> <a href="index.html">Up</a> </div> <center><h1>Module <a href="type_Pcre.html">Pcre</a></h1></center> <br> <pre><span class="keyword">module</span> Pcre: <code class="code">sig</code> <a href="Pcre.html">..</a> <code class="code">end</code></pre>Perl Compatibility Regular Expressions<br> <hr width="100%"> <br> <a name="6_Exceptions"></a> <h6>Exceptions</h6><br> <br><code><span class="keyword">type</span> <a name="TYPEerror"></a><code class="type"></code>error = </code><table class="typetable"> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">Partial</span></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >String only matched the pattern partially</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">BadPartial</span></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Pattern contains items that cannot be used together with partial matching.</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">BadPattern</span> <span class="keyword">of</span> <code class="type">string * int</code></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" ><code class="code">BadPattern (msg, pos)</code> regular expression is malformed. The reason is in <code class="code">msg</code>, the position of the error in the pattern in <code class="code">pos</code>.</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">BadUTF8</span></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >UTF8 string being matched is invalid</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">BadUTF8Offset</span></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Gets raised when a UTF8 string being matched with offset is invalid.</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">MatchLimit</span></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Maximum allowed number of match attempts with backtracking or recursion is reached during matching. ALL FUNCTIONS CALLING THE MATCHING ENGINE MAY RAISE IT!!!</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">RecursionLimit</span></code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">InternalError</span> <span class="keyword">of</span> <code class="type">string</code></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" ><code class="code">InternalError msg</code> C-library exhibits unknown/undefined behaviour. The reason is in <code class="code">msg</code>.</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr></table> <pre><span class="keyword">exception</span> <a name="EXCEPTIONError"></a>Error <span class="keyword">of</span> <code class="type"><a href="Pcre.html#TYPEerror">error</a></code></pre> <div class="info"> Exception indicating PCRE errors.<br> </div> <pre><span class="keyword">exception</span> <a name="EXCEPTIONBacktrack"></a>Backtrack</pre> <div class="info"> <code class="code">Backtrack</code> used in callout functions to force backtracking.<br> </div> <br> <a name="6_Compilationandruntimeflagsandtheirconversionfunctions"></a> <h6>Compilation and runtime flags and their conversion functions</h6><br> <pre><span class="keyword">type</span> <a name="TYPEicflag"></a><code class="type"></code>icflag </pre> <div class="info"> Internal representation of compilation flags<br> </div> <pre><span class="keyword">type</span> <a name="TYPEirflag"></a><code class="type"></code>irflag </pre> <div class="info"> Internal representation of runtime flags<br> </div> <pre><span class="keyword">type</span> <a name="TYPEcflag"></a><code class="type"></code>cflag = <code class="type">[ `ANCHORED<br> | `AUTO_CALLOUT<br> | `CASELESS<br> | `DOLLAR_ENDONLY<br> | `DOTALL<br> | `EXTENDED<br> | `EXTRA<br> | `FIRSTLINE<br> | `MULTILINE<br> | `NO_AUTO_CAPTURE<br> | `NO_UTF8_CHECK<br> | `UNGREEDY<br> | `UTF8 ]</code> </pre> <div class="info"> Compilation flags<br> </div> <pre><span class="keyword">val</span> <a name="VALcflags"></a>cflags : <code class="type"><a href="Pcre.html#TYPEcflag">cflag</a> list -> <a href="Pcre.html#TYPEicflag">icflag</a></code></pre><div class="info"> <code class="code">cflags cflag_list</code> converts a list of compilation flags to their internal representation.<br> </div> <pre><span class="keyword">val</span> <a name="VALcflag_list"></a>cflag_list : <code class="type"><a href="Pcre.html#TYPEicflag">icflag</a> -> <a href="Pcre.html#TYPEcflag">cflag</a> list</code></pre><div class="info"> <code class="code">cflag_list cflags</code> converts internal representation of compilation flags to a list.<br> </div> <pre><span class="keyword">type</span> <a name="TYPErflag"></a><code class="type"></code>rflag = <code class="type">[ `ANCHORED | `NOTBOL | `NOTEMPTY | `NOTEOL | `PARTIAL ]</code> </pre> <div class="info"> Runtime flags<br> </div> <pre><span class="keyword">val</span> <a name="VALrflags"></a>rflags : <code class="type"><a href="Pcre.html#TYPErflag">rflag</a> list -> <a href="Pcre.html#TYPEirflag">irflag</a></code></pre><div class="info"> <code class="code">rflags rflag_list</code> converts a list of runtime flags to their internal representation.<br> </div> <pre><span class="keyword">val</span> <a name="VALrflag_list"></a>rflag_list : <code class="type"><a href="Pcre.html#TYPEirflag">irflag</a> -> <a href="Pcre.html#TYPErflag">rflag</a> list</code></pre><div class="info"> <code class="code">rflag_list rflags</code> converts internal representation of runtime flags to a list.<br> </div> <br> <a name="6_InformationonthePCREconfigurationbuildtimeoptions"></a> <h6>Information on the PCRE-configuration (build-time options)</h6><br> <pre><span class="keyword">val</span> <a name="VALversion"></a>version : <code class="type">string</code></pre><div class="info"> Version information <p> Version of the PCRE-C-library<br> </div> <pre><span class="keyword">val</span> <a name="VALconfig_utf8"></a>config_utf8 : <code class="type">bool</code></pre><div class="info"> Indicates whether UTF8-support is enabled<br> </div> <pre><span class="keyword">val</span> <a name="VALconfig_newline"></a>config_newline : <code class="type">char</code></pre><div class="info"> Character used as newline<br> </div> <pre><span class="keyword">val</span> <a name="VALconfig_link_size"></a>config_link_size : <code class="type">int</code></pre><div class="info"> Number of bytes used for internal linkage of regular expressions<br> </div> <pre><span class="keyword">val</span> <a name="VALconfig_match_limit"></a>config_match_limit : <code class="type">int</code></pre><div class="info"> Default limit for calls to internal matching function<br> </div> <pre><span class="keyword">val</span> <a name="VALconfig_stackrecurse"></a>config_stackrecurse : <code class="type">bool</code></pre><div class="info"> Indicates use of stack recursion in matching function<br> </div> <br> <a name="6_Informationonpatterns"></a> <h6>Information on patterns</h6><br> <pre><span class="keyword">type</span> <a name="TYPEfirstbyte_info"></a><code class="type"></code>firstbyte_info = <code class="type">[ `ANCHORED | `Char of char | `Start_only ]</code> </pre> <div class="info"> Information on matching of "first chars" in patterns<br> </div> <pre><span class="keyword">type</span> <a name="TYPEstudy_stat"></a><code class="type"></code>study_stat = <code class="type">[ `Not_studied | `Optimal | `Studied ]</code> </pre> <div class="info"> Information on the study status of patterns<br> </div> <pre><span class="keyword">type</span> <a name="TYPEregexp"></a><code class="type"></code>regexp </pre> <div class="info"> Compiled regular expressions<br> </div> <pre><span class="keyword">val</span> <a name="VALoptions"></a>options : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> <a href="Pcre.html#TYPEicflag">icflag</a></code></pre><div class="info"> <code class="code">options regexp</code><br> <b>Returns</b> compilation flags of <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALsize"></a>size : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int</code></pre><div class="info"> <code class="code">size regexp</code><br> <b>Returns</b> memory size of <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALstudysize"></a>studysize : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int</code></pre><div class="info"> <code class="code">studysize regexp</code><br> <b>Returns</b> memory size of study information of <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALcapturecount"></a>capturecount : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int</code></pre><div class="info"> <code class="code">capturecount regexp</code><br> <b>Returns</b> number of capturing subpatterns in <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALbackrefmax"></a>backrefmax : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int</code></pre><div class="info"> <code class="code">backrefmax regexp</code><br> <b>Returns</b> number of highest backreference in <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALnamecount"></a>namecount : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int</code></pre><div class="info"> <code class="code">namecount regexp</code><br> <b>Returns</b> number of named subpatterns in <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALnames"></a>names : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> string array</code></pre><div class="info"> <code class="code">names regex</code><br> <b>Returns</b> array of names of named substrings in <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALnameentrysize"></a>nameentrysize : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int</code></pre><div class="info"> <code class="code">nameentrysize regexp</code><br> <b>Returns</b> size of longest name of named subpatterns in <code class="code">regexp</code> + 3.<br> </div> <pre><span class="keyword">val</span> <a name="VALfirstbyte"></a>firstbyte : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> <a href="Pcre.html#TYPEfirstbyte_info">firstbyte_info</a></code></pre><div class="info"> <code class="code">firstbyte regexp</code><br> <b>Returns</b> firstbyte info on <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALfirsttable"></a>firsttable : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> string option</code></pre><div class="info"> <code class="code">firsttable regexp</code><br> <b>Returns</b> some 256-bit (32-byte) fixed set table in form of a string for <code class="code">regexp</code> if available, <code class="code">None</code> otherwise.<br> </div> <pre><span class="keyword">val</span> <a name="VALlastliteral"></a>lastliteral : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> char option</code></pre><div class="info"> <code class="code">lastliteral regexp</code><br> <b>Returns</b> some last matching character of <code class="code">regexp</code> if available, <code class="code">None</code> otherwise.<br> </div> <pre><span class="keyword">val</span> <a name="VALstudy_stat"></a>study_stat : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> <a href="Pcre.html#TYPEstudy_stat">study_stat</a></code></pre><div class="info"> <code class="code">study_stat regexp</code><br> <b>Returns</b> study status of <code class="code">regexp</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALget_stringnumber"></a>get_stringnumber : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> string -> int</code></pre><div class="info"> <code class="code">get_stringnumber rex name</code><br> <b>Raises</b> <code>Invalid_arg</code> if there is no such named substring.<br> <b>Returns</b> the index of the named substring <code class="code">name</code> in regular expression <code class="code">rex</code>. This index can then be used with <code class="code">get_substring</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALget_match_limit"></a>get_match_limit : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int option</code></pre><div class="info"> <code class="code">get_match_limit rex</code><br> <b>Returns</b> some match limit of regular expression <code class="code">rex</code> or <code class="code">None</code>.<br> </div> <br> <a name="6_Compilationofpatterns"></a> <h6>Compilation of patterns</h6><br> <pre><span class="keyword">type</span> <a name="TYPEchtables"></a><code class="type"></code>chtables </pre> <div class="info"> Alternative set of char tables for pattern matching<br> </div> <pre><span class="keyword">val</span> <a name="VALmaketables"></a>maketables : <code class="type">unit -> <a href="Pcre.html#TYPEchtables">chtables</a></code></pre><div class="info"> Generates new set of char tables for the current locale.<br> </div> <pre><span class="keyword">val</span> <a name="VALregexp"></a>regexp : <code class="type">?study:bool -><br> ?limit:int -><br> ?iflags:<a href="Pcre.html#TYPEicflag">icflag</a> -><br> ?flags:<a href="Pcre.html#TYPEcflag">cflag</a> list -> ?chtables:<a href="Pcre.html#TYPEchtables">chtables</a> -> string -> <a href="Pcre.html#TYPEregexp">regexp</a></code></pre><div class="info"> <code class="code">regexp ?study ?limit ?iflags ?flags ?chtables pattern</code> compiles <code class="code">pattern</code> with <code class="code">flags</code> when given, with <code class="code">iflags</code> otherwise, and with char tables <code class="code">chtables</code>. If <code class="code">study</code> is true, then the resulting regular expression will be studied. If <code class="code">limit</code> is specified, this sets a limit to the amount of recursion and backtracking (only lower than the builtin default!). If this limit is exceeded, <code class="code">MatchLimit</code> will be raised during matching.<br> <b>Returns</b> the regular expression. <p> For detailed documentation on how you can specify PERL-style regular expressions (= patterns), please consult the PCRE-documentation ("man pcrepattern") or PERL-manuals.<br> <b>See also</b> <a href="http://www.perl.com">www.perl.com</a><br> </div> <div class="param_info"><code class="code">study</code> : default = true</div> <div class="param_info"><code class="code">limit</code> : default = no extra limit other than default</div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">chtables</code> : default = builtin char tables</div> <pre><span class="keyword">val</span> <a name="VALquote"></a>quote : <code class="type">string -> string</code></pre><div class="info"> <code class="code">quote str</code><br> <b>Returns</b> the quoted string of <code class="code">str</code>.<br> </div> <br> <a name="6_Subpatternextraction"></a> <h6>Subpattern extraction</h6><br> <pre><span class="keyword">type</span> <a name="TYPEsubstrings"></a><code class="type"></code>substrings </pre> <div class="info"> Information on substrings after pattern matching<br> </div> <pre><span class="keyword">val</span> <a name="VALget_subject"></a>get_subject : <code class="type"><a href="Pcre.html#TYPEsubstrings">substrings</a> -> string</code></pre><div class="info"> <code class="code">get_subject substrings</code><br> <b>Returns</b> the subject string of <code class="code">substrings</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALnum_of_subs"></a>num_of_subs : <code class="type"><a href="Pcre.html#TYPEsubstrings">substrings</a> -> int</code></pre><div class="info"> <code class="code">num_of_subs substrings</code><br> <b>Returns</b> number of strings in <code class="code">substrings</code> (whole match inclusive).<br> </div> <pre><span class="keyword">val</span> <a name="VALget_substring"></a>get_substring : <code class="type"><a href="Pcre.html#TYPEsubstrings">substrings</a> -> int -> string</code></pre><div class="info"> <code class="code">get_substring substrings n</code><br> <b>Raises</b><ul><li><code>Invalid_argument</code> if <code class="code">n</code> is not in the range of the number of substrings.</li> <li><code>Not_found</code> if the corresponding subpattern did not capture a substring.</li> </ul> <b>Returns</b> the <code class="code">n</code>th substring (0 is whole match) of <code class="code">substrings</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALget_substring_ofs"></a>get_substring_ofs : <code class="type"><a href="Pcre.html#TYPEsubstrings">substrings</a> -> int -> int * int</code></pre><div class="info"> <code class="code">get_substring_ofs substrings n</code><br> <b>Raises</b><ul><li><code>Invalid_argument</code> if <code class="code">n</code> is not in the range of the number of substrings.</li> <li><code>Not_found</code> if the corresponding subpattern did not capture a substring.</li> </ul> <b>Returns</b> the offset tuple of the <code class="code">n</code>th substring of <code class="code">substrings</code> (0 is whole match).<br> </div> <pre><span class="keyword">val</span> <a name="VALget_substrings"></a>get_substrings : <code class="type">?full_match:bool -> <a href="Pcre.html#TYPEsubstrings">substrings</a> -> string array</code></pre><div class="info"> <code class="code">get_substrings ?full_match substrings</code><br> <b>Returns</b> the array of substrings in <code class="code">substrings</code>. It includes the full match at index 0 when <code class="code">full_match</code> is <code class="code">true</code>, the captured substrings only when it is <code class="code">false</code>. If a subpattern did not capture a substring, the empty string is returned in the corresponding position instead.<br> </div> <div class="param_info"><code class="code">full_match</code> : default = true</div> <pre><span class="keyword">val</span> <a name="VALget_opt_substrings"></a>get_opt_substrings : <code class="type">?full_match:bool -> <a href="Pcre.html#TYPEsubstrings">substrings</a> -> string option array</code></pre><div class="info"> <code class="code">get_opt_substrings ?full_match substrings</code><br> <b>Returns</b> the array of optional substrings in <code class="code">substrings</code>. It includes <code class="code">Some full_match_str</code> at index 0 when <code class="code">full_match</code> is <code class="code">true</code>, <code class="code">Some captured_substrings</code> only when it is <code class="code">false</code>. If a subpattern did not capture a substring, <code class="code">None</code> is returned in the corresponding position instead.<br> </div> <div class="param_info"><code class="code">full_match</code> : default = true</div> <pre><span class="keyword">val</span> <a name="VALget_named_substring"></a>get_named_substring : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> string -> <a href="Pcre.html#TYPEsubstrings">substrings</a> -> string</code></pre><div class="info"> <code class="code">get_named_substring rex name substrings</code><br> <b>Raises</b><ul><li><code>Invalid_argument</code> if there is no such named substring.</li> <li><code>Not_found</code> if the corresponding subpattern did not capture a substring.</li> </ul> <b>Returns</b> the named substring <code class="code">name</code> in regular expression <code class="code">rex</code> and <code class="code">substrings</code>.<br> </div> <pre><span class="keyword">val</span> <a name="VALget_named_substring_ofs"></a>get_named_substring_ofs : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> string -> <a href="Pcre.html#TYPEsubstrings">substrings</a> -> int * int</code></pre><div class="info"> <code class="code">get_named_substring_ofs rex name substrings</code><br> <b>Raises</b><ul><li><code>Invalid_argument</code> if there is no such named substring.</li> <li><code>Not_found</code> if the corresponding subpattern did not capture a substring.</li> </ul> <b>Returns</b> the offset tuple of the named substring <code class="code">name</code> in regular expression <code class="code">rex</code> and <code class="code">substrings</code>.<br> </div> <br> <a name="6_Callouts"></a> <h6>Callouts</h6><br> <br><code><span class="keyword">type</span> <a name="TYPEcallout_data"></a><code class="type"></code>callout_data = {</code><table class="typetable"> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>callout_number : <code class="type">int</code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Callout number</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>substrings : <code class="type"><a href="Pcre.html#TYPEsubstrings">substrings</a></code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Substrings matched so far</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>start_match : <code class="type">int</code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Subject start offset of current match attempt</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>current_position : <code class="type">int</code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Subject offset of current match pointer</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>capture_top : <code class="type">int</code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Number of the highest captured substring so far</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>capture_last : <code class="type">int</code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Number of the most recently captured substring</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>pattern_position : <code class="type">int</code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Offset of next match item in pattern string</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code> </code></td> <td align="left" valign="top" > <code>next_item_length : <code class="type">int</code>;</code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Length of next match item in pattern string</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr></table> } <pre><span class="keyword">type</span> <a name="TYPEcallout"></a><code class="type"></code>callout = <code class="type"><a href="Pcre.html#TYPEcallout_data">callout_data</a> -> unit</code> </pre> <div class="info"> Type of callout functions <p> Callouts are referred to in patterns as "(?Cn)" where "n" is a <code class="code">callout_number</code> ranging from 0 to 255. Substrings captured so far are accessible as usual via <code class="code">substrings</code>. You will have to consider <code class="code">capture_top</code> and <code class="code">capture_last</code> to know about the current state of valid substrings. <p> By raising exception <code class="code">Backtrack</code> within a callout function, the user can force the pattern matching engine to backtrack to other possible solutions. Other exceptions will terminate matching immediately and return control to OCaml.<br> </div> <br> <a name="6_Matchingofpatternsandsubpatternextraction"></a> <h6>Matching of patterns and subpattern extraction</h6><br> <pre><span class="keyword">val</span> <a name="VALpcre_exec"></a>pcre_exec : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -> ?pos:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> int array</code></pre><div class="info"> <code class="code">pcre_exec ?iflags ?flags ?rex ?pat ?pos ?callout subj</code><br> <b>Raises</b> <code>Not_found</code> if pattern does not match.<br> <b>Returns</b> an array of offsets that describe the position of matched subpatterns in the string <code class="code">subj</code> starting at position <code class="code">pos</code> with pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. The array also contains additional workspace needed by the match engine. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALexec"></a>exec : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -> ?pos:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> <a href="Pcre.html#TYPEsubstrings">substrings</a></code></pre><div class="info"> <code class="code">exec ?iflags ?flags ?rex ?pat ?pos ?callout subj</code><br> <b>Raises</b> <code>Not_found</code> if pattern does not match.<br> <b>Returns</b> substring information on string <code class="code">subj</code> starting at position <code class="code">pos</code> with pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALexec_all"></a>exec_all : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> <a href="Pcre.html#TYPEsubstrings">substrings</a> array</code></pre><div class="info"> <code class="code">exec_all ?iflags ?flags ?rex ?pat ?pos ?callout subj</code><br> <b>Raises</b> <code>Not_found</code> if pattern does not match.<br> <b>Returns</b> an array of substring information of all matching substrings in string <code class="code">subj</code> starting at position <code class="code">pos</code> with pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALnext_match"></a>next_match : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> <a href="Pcre.html#TYPEsubstrings">substrings</a> -> <a href="Pcre.html#TYPEsubstrings">substrings</a></code></pre><div class="info"> <code class="code">next_match ?iflags ?flags ?rex ?pat ?pos ?callout substrs</code><br> <b>Raises</b><ul><li><code>Not_found</code> if pattern does not match.</li> <li><code>Invalid_arg</code> if <code class="code">pos</code> let matching start outside of the subject string.</li> </ul> <b>Returns</b> substring information on the match that follows on the last match denoted by <code class="code">substrs</code>, jumping over <code class="code">pos</code> characters (also backwards!), using pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALextract"></a>extract : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?full_match:bool -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string array</code></pre><div class="info"> <code class="code">extract ?iflags ?flags ?rex ?pat ?pos ?full_match ?callout subj</code><br> <b>Raises</b> <code>Not_found</code> if pattern does not match.<br> <b>Returns</b> the array of substrings that match <code class="code">subj</code> starting at position <code class="code">pos</code>, using pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. It includes the full match at index 0 when <code class="code">full_match</code> is <code class="code">true</code>, the captured substrings only when it is <code class="code">false</code>. Callouts are handled by <code class="code">callout</code>. If a subpattern did not capture a substring, the empty string is returned in the corresponding position instead.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">full_match</code> : default = true</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALextract_opt"></a>extract_opt : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?full_match:bool -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string option array</code></pre><div class="info"> <code class="code">extract_opt ?iflags ?flags ?rex ?pat ?pos ?full_match ?callout subj</code><br> <b>Raises</b> <code>Not_found</code> if pattern does not match.<br> <b>Returns</b> the array of optional substrings that match <code class="code">subj</code> starting at position <code class="code">pos</code>, using pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. It includes <code class="code">Some full_match_str</code> at index 0 when <code class="code">full_match</code> is <code class="code">true</code>, <code class="code">Some captured-substrings</code> only when it is <code class="code">false</code>. Callouts are handled by <code class="code">callout</code>. If a subpattern did not capture a substring, <code class="code">None</code> is returned in the corresponding position instead.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">full_match</code> : default = true</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALextract_all"></a>extract_all : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?full_match:bool -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string array array</code></pre><div class="info"> <code class="code">extract_all ?iflags ?flags ?rex ?pat ?pos ?full_match ?callout subj</code><br> <b>Raises</b> <code>Not_found</code> if pattern does not match.<br> <b>Returns</b> an array of arrays of all matching substrings that match <code class="code">subj</code> starting at position <code class="code">pos</code>, using pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. It includes the full match at index 0 of the extracted string arrays when <code class="code">full_match</code> is <code class="code">true</code>, the captured substrings only when it is <code class="code">false</code>. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">full_match</code> : default = true</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALextract_all_opt"></a>extract_all_opt : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?full_match:bool -><br> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string option array array</code></pre><div class="info"> <code class="code">extract_all_opt ?iflags ?flags ?rex ?pat ?pos ?full_match ?callout subj</code><br> <b>Raises</b> <code>Not_found</code> if pattern does not match.<br> <b>Returns</b> an array of arrays of all optional matching substrings that match <code class="code">subj</code> starting at position <code class="code">pos</code>, using pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. It includes <code class="code">Some full_match_str</code> at index 0 of the extracted string arrays when <code class="code">full_match</code> is <code class="code">true</code>, <code class="code">Some captured_substrings</code> only when it is <code class="code">false</code>. Callouts are handled by <code class="code">callout</code>. If a subpattern did not capture a substring, <code class="code">None</code> is returned in the corresponding position instead.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">full_match</code> : default = true</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALpmatch"></a>pmatch : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -> ?pos:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> bool</code></pre><div class="info"> <code class="code">pmatch ?iflags ?flags ?rex ?pat ?pos ?callout subj</code><br> <b>Returns</b> <code class="code">true</code> if <code class="code">subj</code> is matched by pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code>. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <br> <a name="6_Stringsubstitution"></a> <h6>String substitution</h6><br> <pre><span class="keyword">type</span> <a name="TYPEsubstitution"></a><code class="type"></code>substitution </pre> <div class="info"> Information on substitution patterns<br> </div> <pre><span class="keyword">val</span> <a name="VALsubst"></a>subst : <code class="type">string -> <a href="Pcre.html#TYPEsubstitution">substitution</a></code></pre><div class="info"> <code class="code">subst str</code> converts the string <code class="code">str</code> representing a substitution pattern to the internal representation <p> The contents of the substitution string <code class="code">str</code> can be normal text mixed with any of the following (mostly as in PERL): <p> <ul> <li><em>$[0-9]+</em> - a "$" immediately followed by an arbitrary number. "$0" stands for the name of the executable, any other number for the n-th backreference.</li> <li><em>$&</em> - the whole matched pattern</li> <li><em>$`</em> - the text before the match</li> <li><em>$'</em> - the text after the match</li> <li><em>$+</em> - the last group that matched</li> <li><em>$$</em> - a single "$"</li> <li><em>$!</em> - delimiter which does not appear in the substitution. Can be used to part "$<code class="code">0-9</code>+" from an immediately following other number.</li> </ul> <br> </div> <pre><span class="keyword">val</span> <a name="VALreplace"></a>replace : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?itempl:<a href="Pcre.html#TYPEsubstitution">substitution</a> -><br> ?templ:string -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string</code></pre><div class="info"> <code class="code">replace ?iflags ?flags ?rex ?pat ?pos ?itempl ?templ ?callout subj</code> replaces all substrings of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the substitution string <code class="code">templ</code> when given, <code class="code">itempl</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> <b>Raises</b> <code>Failure</code> if there are backreferences to nonexistent subpatterns.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">itempl</code> : default = empty string</div> <div class="param_info"><code class="code">templ</code> : default = ignored</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALqreplace"></a>qreplace : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -> ?templ:string -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string</code></pre><div class="info"> <code class="code">qreplace ?iflags ?flags ?rex ?pat ?pos ?templ ?callout subj</code> replaces all substrings of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the string <code class="code">templ</code>. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">templ</code> : default = ignored</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALsubstitute_substrings"></a>substitute_substrings : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -><br> subst:(<a href="Pcre.html#TYPEsubstrings">substrings</a> -> string) -> string -> string</code></pre><div class="info"> <code class="code">substitute_substrings ?iflags ?flags ?rex ?pat ?pos ?callout ~subst subj</code> replaces all substrings of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the result of function <code class="code">subst</code> applied to the substrings of the match. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALsubstitute"></a>substitute : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> subst:(string -> string) -> string -> string</code></pre><div class="info"> <code class="code">substitute ?iflags ?flags ?rex ?pat ?pos ?callout ~subst subj</code> replaces all substrings of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the result of function <code class="code">subst</code> applied to the match. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALreplace_first"></a>replace_first : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?itempl:<a href="Pcre.html#TYPEsubstitution">substitution</a> -><br> ?templ:string -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string</code></pre><div class="info"> <code class="code">replace_first ?iflags ?flags ?rex ?pat ?pos ?itempl ?templ ?callout subj</code> replaces the first substring of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the substitution string <code class="code">templ</code> when given, <code class="code">itempl</code> otherwise. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> <b>Raises</b> <code>Failure</code> if there are backreferences to nonexistent subpatterns.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">itempl</code> : default = empty string</div> <div class="param_info"><code class="code">templ</code> : default = ignored</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALqreplace_first"></a>qreplace_first : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -> ?templ:string -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string</code></pre><div class="info"> <code class="code">qreplace_first ?iflags ?flags ?rex ?pat ?pos ?templ ?callout subj</code> replaces the first substring of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the string <code class="code">templ</code>. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">templ</code> : default = ignored</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALsubstitute_substrings_first"></a>substitute_substrings_first : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -><br> subst:(<a href="Pcre.html#TYPEsubstrings">substrings</a> -> string) -> string -> string</code></pre><div class="info"> <code class="code">substitute_substrings_first ?iflags ?flags ?rex ?pat ?pos ?callout ~subst subj</code> replaces the first substring of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the result of function <code class="code">subst</code> applied to the substrings of the match. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALsubstitute_first"></a>substitute_first : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> subst:(string -> string) -> string -> string</code></pre><div class="info"> <code class="code">substitute_first ?iflags ?flags ?rex ?pat ?pos ?callout ~subst subj</code> replaces the first substring of <code class="code">subj</code> matching pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code> with the result of function <code class="code">subst</code> applied to the match. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <br> <a name="6_Splitting"></a> <h6>Splitting</h6><br> <pre><span class="keyword">val</span> <a name="VALsplit"></a>split : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -> ?max:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string list</code></pre><div class="info"> <code class="code">split ?iflags ?flags ?rex ?pat ?pos ?max ?callout subj</code> splits <code class="code">subj</code> into a list of at most <code class="code">max</code> strings, using as delimiter pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code>. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. If <code class="code">max</code> is zero, trailing empty fields are stripped. If it is negative, it is treated as arbitrarily large. If neither <code class="code">pat</code> nor <code class="code">rex</code> are specified, leading whitespace will be stripped! Should behave exactly as in PERL. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">max</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <pre><span class="keyword">val</span> <a name="VALasplit"></a>asplit : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -> ?max:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> string array</code></pre><div class="info"> <code class="code">asplit ?iflags ?flags ?rex ?pat ?pos ?max ?callout subj</code> same as <a href="Pcre.html#VALsplit"><code class="code">Pcre.split</code></a> but<br> <b>Returns</b> an array instead of a list.<br> </div> <br><code><span class="keyword">type</span> <a name="TYPEsplit_result"></a><code class="type"></code>split_result = </code><table class="typetable"> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">Text</span> <span class="keyword">of</span> <code class="type">string</code></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Text part of splitted string</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">Delim</span> <span class="keyword">of</span> <code class="type">string</code></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Delimiter part of splitted string</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">Group</span> <span class="keyword">of</span> <code class="type">int * string</code></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Subgroup of matched delimiter (subgroup_nr, subgroup_str)</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr> <tr> <td align="left" valign="top" > <code><span class="keyword">|</span></code></td> <td align="left" valign="top" > <code><span class="constructor">NoGroup</span></code></td> <td class="typefieldcomment" align="left" valign="top" ><code>(*</code></td><td class="typefieldcomment" align="left" valign="top" >Unmatched subgroup</td><td class="typefieldcomment" align="left" valign="bottom" ><code>*)</code></td> </tr></table> <div class="info"> Result of a <a href="Pcre.html#VALfull_split"><code class="code">Pcre.full_split</code></a><br> </div> <pre><span class="keyword">val</span> <a name="VALfull_split"></a>full_split : <code class="type">?iflags:<a href="Pcre.html#TYPEirflag">irflag</a> -><br> ?flags:<a href="Pcre.html#TYPErflag">rflag</a> list -><br> ?rex:<a href="Pcre.html#TYPEregexp">regexp</a> -><br> ?pat:string -><br> ?pos:int -><br> ?max:int -> ?callout:<a href="Pcre.html#TYPEcallout">callout</a> -> string -> <a href="Pcre.html#TYPEsplit_result">split_result</a> list</code></pre><div class="info"> <code class="code">full_split ?iflags ?flags ?rex ?pat ?pos ?max ?callout subj</code> splits <code class="code">subj</code> into a list of at most <code class="code">max</code> elements of type "split_result", using as delimiter pattern <code class="code">pat</code> when given, regular expression <code class="code">rex</code> otherwise, starting at position <code class="code">pos</code>. Uses <code class="code">flags</code> when given, the precompiled <code class="code">iflags</code> otherwise. If <code class="code">max</code> is zero, trailing empty fields are stripped. If it is negative, it is treated as arbitrarily large. Should behave exactly as in PERL. Callouts are handled by <code class="code">callout</code>.<br> </div> <div class="param_info"><code class="code">iflags</code> : default = no extra flags</div> <div class="param_info"><code class="code">flags</code> : default = ignored</div> <div class="param_info"><code class="code">rex</code> : default = matches whitespace</div> <div class="param_info"><code class="code">pat</code> : default = ignored</div> <div class="param_info"><code class="code">pos</code> : default = 0</div> <div class="param_info"><code class="code">max</code> : default = 0</div> <div class="param_info"><code class="code">callout</code> : default = ignore callouts</div> <br> <a name="6_Additionalconveniencefunctions"></a> <h6>Additional convenience functions</h6><br> <pre><span class="keyword">val</span> <a name="VALforeach_line"></a>foreach_line : <code class="type">?ic:Pervasives.in_channel -> (string -> unit) -> unit</code></pre><div class="info"> <code class="code">foreach_line ?ic f</code> applies <code class="code">f</code> to each line in inchannel <code class="code">ic</code> until the end-of-file is reached.<br> </div> <div class="param_info"><code class="code">ic</code> : default = stdin</div> <pre><span class="keyword">val</span> <a name="VALforeach_file"></a>foreach_file : <code class="type">string list -> (string -> Pervasives.in_channel -> unit) -> unit</code></pre><div class="info"> <code class="code">foreach_file filenames f</code> opens each file in the list <code class="code">filenames</code> for input and applies <code class="code">f</code> to each filename and the corresponding channel. Channels are closed after each operation (even when exceptions occur - they get reraised afterwards!).<br> </div> <br> <a name="6_UNSAFESTUFFUSEWITHCAUTION"></a> <h6><b>UNSAFE STUFF - USE WITH CAUTION!</b></h6><br> <pre><span class="keyword">val</span> <a name="VALunsafe_pcre_exec"></a>unsafe_pcre_exec : <code class="type"><a href="Pcre.html#TYPEirflag">irflag</a> -><br> <a href="Pcre.html#TYPEregexp">regexp</a> -><br> int -> string -> int -> int array -> <a href="Pcre.html#TYPEcallout">callout</a> option -> unit</code></pre><div class="info"> <code class="code">unsafe_pcre_exec flags rex pos subject subgroup_offsets offset_vector</code>. You should read the C-source to know what happens. If you do not understand it - <b>don't use this function!</b><br> </div> <pre><span class="keyword">val</span> <a name="VALmake_ovector"></a>make_ovector : <code class="type"><a href="Pcre.html#TYPEregexp">regexp</a> -> int * int array</code></pre><div class="info"> <code class="code">make_ovector regexp</code> calculates the tuple (subgroups2, ovector) which is the number of subgroup offsets and the offset array.<br> </div> </body></html>