Module Re__.Core
Compilation and execution of a regular expression
val compile : t -> re
Compile a regular expression into an executable version that can be used to match strings, e.g. with
exec
.
val exec : ?pos:int -> ?len:int -> re -> string -> groups
exec re str
matchesstr
against the compiled expressionre
, and returns the matched groups if any.- parameter pos
optional beginning of the string (default 0)
- parameter len
length of the substring of
str
that can be matched (default-1
, meaning to the end of the string
- raises Not_found
if the regular expression can't be found in
str
val exec_opt : ?pos:int -> ?len:int -> re -> string -> groups option
Similar to
exec
, but returns an option instead of using an exception.
val execp : ?pos:int -> ?len:int -> re -> string -> bool
Similar to
exec
, but returnstrue
if the expression matches, andfalse
if it doesn't
val exec_partial : ?pos:int -> ?len:int -> re -> string -> [ `Full | `Partial | `Mismatch ]
More detailed version of
exec_p
module Group : sig ... end
Manipulate matching groups.
module Mark : sig ... end
Marks
High Level Operations
val all : ?pos:int -> ?len:int -> re -> string -> Group.t list
Repeatedly calls
exec
on the given string, starting at given position and length.
val all_gen : ?pos:int -> ?len:int -> re -> string -> Group.t gen
Same as
all
but returns a generator
val all_seq : ?pos:int -> ?len:int -> re -> string -> Group.t Stdlib.Seq.t
Same as
all
but returns an iterator- since
- NEXT_RELEASE
val matches : ?pos:int -> ?len:int -> re -> string -> string list
Same as
all
, but extracts the matched substring rather than returning the whole group. This basically iterates over matched strings
val matches_gen : ?pos:int -> ?len:int -> re -> string -> string gen
Same as
matches
, but returns a generator.
val matches_seq : ?pos:int -> ?len:int -> re -> string -> string Stdlib.Seq.t
Same as
matches
, but returns an iterator- since
- NEXT_RELEASE
val split : ?pos:int -> ?len:int -> re -> string -> string list
split re s
splitss
into chunks separated byre
. It yields the chunks themselves, not the separator. For instance this can be used with a whitespace-matching re such as"[\t ]+"
.
val split_gen : ?pos:int -> ?len:int -> re -> string -> string gen
val split_seq : ?pos:int -> ?len:int -> re -> string -> string Stdlib.Seq.t
- since
- NEXT_RELEASE
type split_token
=[
|
`Text of string
Text between delimiters
|
`Delim of Group.t
Delimiter
]
val split_full : ?pos:int -> ?len:int -> re -> string -> split_token list
val split_full_gen : ?pos:int -> ?len:int -> re -> string -> split_token gen
val split_full_seq : ?pos:int -> ?len:int -> re -> string -> split_token Stdlib.Seq.t
- since
- NEXT_RELEASE
val replace : ?pos:int -> ?len:int -> ?all:bool -> re -> f:(Group.t -> string) -> string -> string
replace ~all re ~f s
iterates ons
, and replaces every occurrence ofre
withf substring
wheresubstring
is the current match. Ifall = false
, then only the first occurrence ofre
is replaced.
val replace_string : ?pos:int -> ?len:int -> ?all:bool -> re -> by:string -> string -> string
replace_string ~all re ~by s
iterates ons
, and replaces every occurrence ofre
withby
. Ifall = false
, then only the first occurrence ofre
is replaced.
String expressions (literal match)
Basic operations on regular expressions
val empty : t
Match nothing
val epsilon : t
Empty word
String, line, word
val bol : t
Beginning of line
val eol : t
End of line
val bow : t
Beginning of word
val eow : t
End of word
val bos : t
Beginning of string
val eos : t
End of string
val leol : t
Last end of line or end of string
val start : t
Initial position
val stop : t
Final position
val not_boundary : t
Not at a word boundary
Match semantics
Repeated match modifiers
Groups (or submatches)
Character sets
val set : string -> t
Any character of the string
val rg : char -> char -> t
Character ranges
Predefined character sets
val any : t
Any character
val notnl : t
Any character but a newline
Case modifiers
Internal debugging
val pp : Stdlib.Format.formatter -> t -> unit
val pp_re : Stdlib.Format.formatter -> re -> unit
val print_re : Stdlib.Format.formatter -> re -> unit
Alias for
pp_re
. Deprecated
Experimental functions
.
val witness : t -> string
witness r
generates a strings
such thatexecp (compile r) s
is true
Deprecated functions
val get_ofs : Group.t -> int -> int * int
Same as
Group.offset
. Deprecated
val get_all_ofs : Group.t -> (int * int) array
Same as
Group.all_offset
. Deprecated
val test : Group.t -> int -> bool
Same as
Group.test
. Deprecated
val mark_set : Group.t -> Mark.Set.t
Same as
Mark.all
. Deprecated