module Netstring_pcre:Wrapper for regexps with PCRE syntaxsig
..end
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.
typeregexp =
Pcre.regexp
Pcre
typesplit_result =
Pcre.split_result
=
| |
Text of |
|||
| |
Delim of |
|||
| |
Group of |
|||
| |
NoGroup |
(* | Here we keep compatiblity with Pcre | *) |
type
result
val regexp : string -> regexp
val regexp_case_fold : string -> regexp
val quote : string -> string
val regexp_string : string -> regexp
val regexp_string_case_fold : string -> regexp
groups
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 option
None
if no match is found. Returns Some r
on success,
and r
describes the match.val search_forward : ?groups:int ->
regexp -> string -> int -> int * result
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 : ?groups:int ->
regexp -> string -> int -> int * result
Not_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 -> string
string_match
or the search
functions, and the result argument must be the corresponding
result.val match_beginning : result -> int
val match_end : result -> int
val matched_group : result -> int -> string -> string
string_match
or the search
functions, and the result argument must be the corresponding
result.val group_beginning : result -> int -> int
val group_end : result -> int -> int
val global_replace : regexp -> string -> string -> string
global_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 -> string
replace_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 -> string
global_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 -> string
substitute_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 list
val bounded_split : regexp -> string -> int -> string list
n
substrings, based on split
val split_delim : regexp -> string -> string list
split
, but occurrences of the delimiter at the beginning
and the end are returned as empty stringsval bounded_split_delim : regexp -> string -> int -> string list
n
substrings, based on split_delim
val full_split : regexp -> string -> split_result list
split_delim
, but returns the delimiters in the resultval bounded_full_split : regexp -> string -> int -> split_result list
n
substrings, based on full_split
val string_before : string -> int -> string
n
characters of a stringval string_after : string -> int -> string
n
characters of a stringval first_chars : string -> int -> string
string_before
val last_chars : string -> int -> string
string_after