package re2
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=8966e3ceade876af6542af41efc350261e5b70c1cd6b42ad698b80e486bba14e
md5=fcf5dc32f1a325f135624f1a3676539e
doc/re2/Re2/index.html
Module Re2
include module type of struct include Regex end
Although OCaml strings and C++ strings may legally have internal null bytes, this library doesn't handle them correctly by doing conversions via C strings. The failure mode is the search stops early, which isn't bad considering how rare internal null bytes are in practice.
The strings are considered according to Options.encoding which is UTF-8 by default (the alternative is ISO 8859-1).
Basic Types
type t = Regex.tinclude Core_kernel.Bin_prot.Binable.S with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
val bin_size_t : t Bin_prot.Size.sizerval bin_write_t : t Bin_prot.Write.writerval bin_read_t : t Bin_prot.Read.readerval __bin_read_t__ : (int -> t) Bin_prot.Read.readerThis function only needs implementation if t exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variant t afterwards.
val bin_shape_t : Bin_prot.Shape.tval bin_writer_t : t Bin_prot.Type_class.writerval bin_reader_t : t Bin_prot.Type_class.readerval bin_t : t Bin_prot.Type_class.tval hash_fold_t :
Ppx_hash_lib.Std.Hash.state ->
t ->
Ppx_hash_lib.Std.Hash.stateval hash : t -> Ppx_hash_lib.Std.Hash.hash_valuetype regex = tSubpatterns are referenced by name if labelled with the /(?P<...>...)/ syntax, or else by counting open-parens, with subpattern zero referring to the whole regex.
index_of_id t id resolves subpattern names and indices into indices. *
The sub keyword argument means, omit location information for subpatterns with index greater than sub.
Subpatterns are indexed by the number of opening parentheses preceding them:
~sub:(`Index 0) : only the whole match ~sub:(`Index 1) : the whole match and the first submatch, etc.
If you only care whether the pattern does match, you can request no location information at all by passing ~sub:(`Index -1).
With one exception, I quote from re2.h:443,
Don't ask for more match information than you will use: runs much faster with nmatch == 1 than nmatch > 1, and runs even faster if nmatch == 0.
For sub > 1, re2 executes in three steps: 1. run a DFA over the entire input to get the end of the whole match 2. run a DFA backward from the end position to get the start position 3. run an NFA from the match start to match end to extract submatches sub == 1 lets it stop after (2) and sub == 0 lets it stop after (1). (See re2.cc:692 or so.)
The one exception is for the functions get_matches, replace, and Iterator.next: Since they must iterate correctly through the whole string, they need at least the whole match (subpattern 0). These functions will silently rewrite ~sub to be non-negative.
module Options : sig ... endSee re2_c/libre2/re2/re2.h for documentation of these options.
val create : ?options:Options.t -> string -> t Core_kernel.Or_error.tinclude Core_kernel.Stringable with type t := t
val of_string : string -> tval to_string : t -> stringval num_submatches : t -> intnum_submatches t returns 1 + the number of open-parens in the pattern.
N.B. num_submatches t == 1 + RE2::NumberOfCapturingGroups() because RE2::NumberOfCapturingGroups() ignores the whole match ("subpattern zero").
val pattern : t -> stringpattern t returns the pattern from which the regex was constructed.
val find_all : ?sub:id_t -> t -> string -> string list Core_kernel.Or_error.tfind_all t input a convenience function that returns all non-overlapping matches of t against input, in left-to-right order.
If sub is given, and the requested subpattern did not capture, then no match is returned at that position even if other parts of the regex did match.
val find_first : ?sub:id_t -> t -> string -> string Core_kernel.Or_error.tfind_first ?sub pattern input finds the first match of pattern in input, and returns the subpattern specified by sub, or an error if the subpattern didn't capture.
val find_submatches : t -> string -> string option array Core_kernel.Or_error.tfind_submatches t input finds the first match and returns all submatches. Element 0 is the whole match and element 1 is the first parenthesized submatch, etc.
val find_submatches_exn : t -> string -> string option arrayval matches : t -> string -> boolmatches pattern input
val split : ?max:int -> ?include_matches:bool -> t -> string -> string listsplit pattern input
If t never matches, the returned list has input as its one element.
val rewrite : t -> template:string -> string -> string Core_kernel.Or_error.trewrite pattern ~template input is a convenience function for replace: Instead of requiring an arbitrary transformation as a function, it accepts a template string with zero or more substrings of the form "\\n", each of which will be replaced by submatch n. For every match of pattern against input, the template will be specialized and then substituted for the matched substring.
val rewrite_exn : t -> template:string -> string -> stringval valid_rewrite_template : t -> template:string -> boolvalid_rewrite_template pattern ~template returns true iff template is a valid rewrite template for pattern
escape nonregex returns a copy of nonregex with everything escaped (i.e., if the return value were t to regex, it would match exactly the original input)
Infix Operators
module Infix = Regex.InfixComplicated Interface
type 'a without_trailing_none = 'a Regex.without_trailing_noneval sexp_of_without_trailing_none :
('a -> Ppx_sexp_conv_lib.Sexp.t) ->
'a without_trailing_none ->
Ppx_sexp_conv_lib.Sexp.tval without_trailing_none : 'a -> 'a without_trailing_noneThis type marks call sites affected by a bugfix that eliminated a trailing None. When you add this wrapper, check that your call site does not still work around the bug by dropping the last element.
module Match = Regex.Matchval get_matches :
?sub:id_t ->
?max:int ->
t ->
string ->
Match.t list Core_kernel.Or_error.tget_matches pattern input returns all non-overlapping matches of pattern against input
val to_sequence_exn :
?sub:id_t ->
t ->
string ->
Match.t Core_kernel.Sequence.tval first_match : t -> string -> Match.t Core_kernel.Or_error.tfirst_match pattern input
val replace :
?sub:id_t ->
?only:int ->
f:(Match.t -> string) ->
t ->
string ->
string Core_kernel.Or_error.treplace ?sub ?max ~f pattern input
module Exceptions = Regex.Exceptionsmodule Multiple = Regex.Multiplemodule Parser : sig ... endmodule Std : sig ... endmodule Regex : sig ... end