module Netstring_str:Wrapper for regexps withsig..end
Str syntax
This module was written at a time when we had only the Str module
for regular expressions. However, Str has an interface that does
not work for multi-threaded programs, because the state of the module
is visible to the outside. The module Netstring_str is similar to Str,
but has a thread-compatible interface.
Now we have the much better PCRE library for regular expressions.
This implementation of Netstring_str bases on the PCRE engine but retains
the old interface as much as possible. This includes that the regexp
function parses old-style regular expressions and internally translates
them to PCRE-style expressions.
See also Netstring_pcre. The difference is that Netstring_pcre expects
already PCRE-style regular expressions and does not translate them.
. matches every character but newline
e* matches e several times
e+ matches e several times but at least once
e? matches e optionally
e{m,n} matches e at least m times and at most n times
e1\|e2 matches e1 or e2
[set] matches the characters from set
[^set] matches the characters except from set
\(...\) group paranthesis
\n back reference
\w matches word (= alphanumeric characters (and underscore))
\W matches characters except \w
\b matches at word boundary
\B matches everywhere but not at word boundary
\< matches at beginning of word
\> matches at end of word
^ matches at beginning of line
$ matches at end of line
\` matches at beginning of buffer
\' matches at end of buffer
This is exactly what Str supports with one exception. Character classes
are not implemented.
typeregexp =Pcre.regexp
Pcretypesplit_result =Str.split_result=
| |
Text of |
|||
| |
Delim of |
(* | Here we keep compatibility with Str | *) |
type result
val regexp : string -> regexpval regexp_case_fold : string -> regexpval quote : string -> stringval regexp_string : string -> regexpval regexp_string_case_fold : string -> regexpgroups argument is ignored in the following functions.
Once upon a time this argument determined how many groups were
copied to the result value.
Now all groups are accessible in the result value, no matter
what groups says.val string_match : ?groups:int ->
regexp -> string -> int -> result optionNone if no match is found. Returns Some r on success,
and r describes the match.val search_forward : ?groups:int ->
regexp -> string -> int -> int * resultNot_found if no match could be found.
Returns (p,r) when a match at position p is found,
described by r.val search_backward : ?groups:int ->
regexp -> string -> int -> int * resultNot_found if no match could be found.
Returns (p,r) when a match at position p is found,
described by r.val matched_string : result -> string -> stringstring_match or the search
functions, and the result argument must be the corresponding
result.val match_beginning : result -> intval match_end : result -> intval matched_group : result -> int -> string -> stringstring_match or the search
functions, and the result argument must be the corresponding
result.val group_beginning : result -> int -> intval group_end : result -> int -> intval global_replace : regexp -> string -> string -> stringglobal_replace re templ s: Replaces all matchings of re in
s by templ.
In templ one can refer to matched groups by the backslash notation:
\1 refers to the first group, \2 to the second etc.
\0 is the whole match. \\ is the backslash character.
val replace_first : regexp -> string -> string -> stringreplace_first re templ s: Replaces the first match of re in
s by templ.
In templ one can refer to matched groups by the backslash notation:
\1 refers to the first group, \2 to the second etc.
\0 is the whole match. \\ is the backslash character.
val global_substitute : ?groups:int ->
regexp ->
(result -> string -> string) -> string -> stringglobal_substitute re subst s: Applies the substitution function
subst to all matchings of re in s, and returns the
transformed string. subst is called with the current result
of the match and the whole string s.val substitute_first : ?groups:int ->
regexp ->
(result -> string -> string) -> string -> stringsubstitute_first re subst s: Applies the substitution function
subst to the first matching of re in s, and returns the
transformed string. subst is called with the current result
of the match and the whole string s.val split : regexp -> string -> string listval bounded_split : regexp -> string -> int -> string listn substrings, based on splitval split_delim : regexp -> string -> string listsplit, but occurrences of the delimiter at the beginning
and the end are returned as empty stringsval bounded_split_delim : regexp -> string -> int -> string listn substrings, based on split_delimval full_split : regexp -> string -> split_result listsplit_delim, but returns the delimiters in the resultval bounded_full_split : regexp -> string -> int -> split_result listn substrings, based on full_splitval string_before : string -> int -> stringn characters of a stringval string_after : string -> int -> stringn characters of a stringval first_chars : string -> int -> stringstring_beforeval last_chars : string -> int -> stringstring_after