package re2
Module Re2.ParserSource
include Core.Applicative.Let_syntax
with type 'a t := 'a t
with module Open_on_rhs_intf := Open_on_rhs_intf
module Let_syntax : sig ... endinclude Open_on_rhs_intf.S with type 'a t := 'a t
include Regex_parser_intf.S with type 'a t := 'a t
val compile :
?case_sensitive:Base.bool ->
'a t ->
(Base.string -> 'a Base.option) Base.Staged.tcase_sensitive defaults to true.
The applicative interface provides sequencing, e.g. both a b is a regex that parses an a followed by a b and returns both results in a pair.
include Base.Applicative.S with type 'a t := 'a t
val return : 'a -> 'a tmodule Applicative_infix : sig ... endignore_m t is a regex which matches the same strings that t matches, but doesn't call functions on the captured submatches. Particularly, something like ignore (map (string "x") ~f:Int.of_string) won't raise an exception, because the int conversion is never attempted.
capture t returns the string matched by t
and_capture t returns the string matched by t in addition to whatever it was already going to return.
greedy defaults to true. If false, the regexp will prefer not matching.
val repeat :
?greedy:Base.bool ->
?min:Base.int ->
?max:Base.int Base.option ->
Base.unit t ->
Base.unit trepeat ~min ~max t constructs the regex t{min,max}. min defaults to 0 and max defaults to None (unbounded), so that just plain repeat t is equivalent to t*.
It would be better for repeat to be 'a t -> 'a list t, but the Re2 library, for example, doesn't give you access to repeated submatches like that. Hence, repeat ignores all submatches of its argument and does not call any callbacks that may have been attached to them, as if it had ignore called on its result.
times r n essentially constructs the regex r{n}. It is equivalent to repeat ~min:n ~max:(Some n) r.
Compare with, say, all (List.init n ~f:(fun _ -> r)), which constructs the regex rrr...r (with n copies of r) and has the type 'a t -> 'a list t.
to_regex_string and to_re2 both forget what a 'a t knows about turning the matching strings into 'as
of_re2 r forgets the options that r was compiled with, instead using `Encoding_latin1 true, `Dot_nl true, and the case-sensitivity setting of the overall pattern. You can still try and use '(?flags:re)' Re2 syntax to set options for the scope of this regex.
The returned values are precisely the captures of the underlying regex, in order: note that unlike (say) Re2.Match.get_all, the whole match is *not* included (if you want that, just use capture). Named captures are not accessible by name.