module Netstring_pcre:sig..end
Wrapper for regexps with PCRE syntax
This module is a version of Str with a thread-safe interface,
implemented using Pcre.
This modules processes PCRE-style regular expressions. If you like
to write Str-like regexps, you can also use Netstring_str with
almost the same signature.
The functions in this module are unavailable if Ocamlnet is built
with Str as implementation of regular expressions! They will always
raise Invalid_argument!
Supported regexp syntax: See pcrepattern(3).
typeregexp =Pcre.regexp
The type of regular expressions; now based on Pcre
typesplit_result =Pcre.split_result=
| |
Text of |
|||
| |
Delim of |
|||
| |
Group of |
|||
| |
NoGroup |
(* | Here we keep compatiblity with | *) |
type result
The type of matching results
val regexp : string -> regexpParses a regexp
val regexp_case_fold : string -> regexpParses a case-insensitive regexp
val quote : string -> stringQuotes a string such that it can be included in a regexp
val regexp_string : string -> regexpReturns a regexp that matches exactly the string
val regexp_string_case_fold : string -> regexpReturns a case-insensitive regexp that matches exactly the string
val string_match : regexp -> string -> int -> result optionMatches the string at the position with the regexp. Returns
None if no match is found. Returns Some r on success,
and r describes the match.
val bytes_match : regexp ->
Stdlib.Bytes.t -> int -> result optionSame for bytes
val search_forward : regexp -> string -> int -> int * resultSearches a match of the string with the regexp, starting at
the position and in forward direction.
Raises Not_found if no match could be found.
Returns (p,r) when a match at position p is found,
described by r.
val search_forward_bytes : regexp -> Stdlib.Bytes.t -> int -> int * resultSame for bytes
val search_backward : regexp -> string -> int -> int * resultSearches a match of the string with the regexp, starting at
the position and in backward direction.
Raises Not_found if no match could be found.
Returns (p,r) when a match at position p is found,
described by r.
val search_backward_bytes : regexp -> Stdlib.Bytes.t -> int -> int * resultSame for bytes
val matched_string : result -> string -> stringExtracts the matched part from the string. The string argument
must be the same string passed to string_match or the search
functions, and the result argument must be the corresponding
result.
val matched_bytes : result -> Stdlib.Bytes.t -> Stdlib.Bytes.tSame for bytes
val match_beginning : result -> intReturns the position where the matched part begins
val match_end : result -> intReturns the position where the matched part ends
val matched_group : result -> int -> string -> stringExtracts the substring the nth group matches from the whole
string. The string argument
must be the same string passed to string_match or the search
functions, and the result argument must be the corresponding
result.
val matched_group_bytes : result -> int -> Stdlib.Bytes.t -> Stdlib.Bytes.tSame for bytes
val group_beginning : result -> int -> intReturns the position where the substring matching the nth group begins
val group_end : result -> int -> intReturns the position where the substring matching the nth group ends
val 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 : 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 : 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 listSplits the string according to the regexp in substrings. Occurrences of the delimiter at the beginning and the end are ignored.
val bounded_split : regexp -> string -> int -> string listSplits into at most n substrings, based on split
val split_delim : regexp -> string -> string listSame as split, but occurrences of the delimiter at the beginning
and the end are returned as empty strings
val bounded_split_delim : regexp -> string -> int -> string listSplits into at most n substrings, based on split_delim
val full_split : regexp -> string -> split_result listLike split_delim, but returns the delimiters in the result
val bounded_full_split : regexp -> string -> int -> split_result listSplits into at most n substrings, based on full_split
val string_before : string -> int -> stringThe first n characters of a string
val string_after : string -> int -> stringThe last n characters of a string
val first_chars : string -> int -> stringSame as string_before
val last_chars : string -> int -> stringSame as string_after