module Extra:Extra definitions.sig
..end
typeresult =
(int * string * string list * int) option
None
which means that the matching have failed
Some(a,x,gl,b)
which means that:
x
of the input string
that matches the regular expression;a
and b
(the frame) are the positions (indexes)
of the beginning and the end of the substring x
w.r.t. the input string;gl
is the list of substrings which have matched the groups defined in
the regular expression; the length of this list will be equal to the number of groups
defined in the regular expression.
# let r = mkregexp ["("] ["[0-9]*"; "[,]?"; "[0-9]*"] [")"] ;;
# match_whole r "abcd";;
: result = None
# match_whole r "(16,7)";;
: result = Some (0, "(16,7)", ["16"; ","; "7"], 5)
val mkregexp : ?strict:bool -> string list -> string list -> string list -> Str.regexp
mkregexp pl gl sl
causes the following actions: pl
are simply catenated in a unique string (the prefix) gl
are catenated enclosing each one into "\\("
and "\\)"
in order to define distinct groupssl
are simply catenated in a unique string (the suffix)strict
, set to true
by default, means that
the regular expression will be matched exactly. In other words, the string obtained
as described above, by default is finally enclosed into "^"
and "$"
.val matched_groups : int -> string -> string list
matched_groups i x
returns the list
of substrings of x
matching groups starting from the group number i
.
See the standard Str.matched_group
for more details.val match_frame : Str.regexp -> string -> int * int -> result
match_frame r s (a,b)
try to match the substring (a,b)
of the string s
with the compiled regular expression r
.val match_whole : Str.regexp -> string -> result
match_whole r s (a,b)
try to match the whole string s
with the compiled regular expression r
.val match_string : string -> string -> result
match_whole
but the regular expression is given as a simple string and compiled
on the fly before invoking match_whole
. In other words, match_string e s
is simpy
a shortcut for match_whole (Str.regexp e) s
.val extract_groups : Str.regexp -> string -> string list
\((..\))
.
If the input string does not match, the empty list is returned.
Example:
# extract_groups (Str.regexp "aa\\([0-9]*\\)bb\\([A-Z]*\\)cc") "aa12bbZcc";;
: string list = ["12"; "Z"]
module Bool:sig
..end
true
stands for <>None
).
val minus : string -> string -> string
minus x y
delete the rightmost occurrence of the pattern y
into the string x
.
Examples:
# minus "foo.bar.txt" "[.][a-z]*";;
: string = "foo.bar"
# minus "/usr/local/bin" "[/][a-z]*";;
: string = "/usr/local"
val grep : string -> string list -> string list
Examples:
# grep "[0-9]" ["aa";"bb";"c8";"dd";"1e"] ;;
: string list = ["c8"; "1e"]
# grep "[0-9]$" ["aa";"bb";"c8";"dd";"1e"] ;;
: string list = ["c8"]
# "ls" => ( Sys.run || fst || String.to_list || grep ".*mli$" ) ;;
: string list = ["foo.mli"; "bar.mli"]
val wellFormedName : ?allow_dash:bool -> string -> bool