Module StrExtra.Extra (.ml)


module Extra: sig .. end
Extra definitions.

type result = (int * string * string list * int) option 
The result of a matching of a regular expression with a string may be:

None which means that the matching have failed

Some(a,x,gl,b) which means that:

Example:

# 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)



Building


val mkregexp : ?strict:bool -> string list -> string list -> string list -> Str.regexp
Facility for building regular expressions. The call mkregexp pl gl sl causes the following actions:

Matching


val matched_groups : int -> string -> string list
The call 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
The heuristic 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
The heuristic 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
Similar to 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
Extract parts of a string using a regexp containing some group expressions \((..\)). 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"]


Boolean versions


module Bool: sig .. end
Boolean versions of matching heuristics (true stands for <>None).

Stuff


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
Grep on string lists: only strings matching the pattern are selected.

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
Check if a string can be used as an identifier.