Module Re__.Core
Compilation and execution of a regular expression
val compile : t -> reCompile 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 -> groupsexec re strmatchesstragainst 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
strthat 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 optionSimilar to
exec, but returns an option instead of using an exception.
val execp : ?pos:int -> ?len:int -> re -> string -> boolSimilar to
exec, but returnstrueif the expression matches, andfalseif it doesn't
val exec_partial : ?pos:int -> ?len:int -> re -> string -> [ `Full | `Partial | `Mismatch ]More detailed version of
exec_p
module Group : sig ... endManipulate matching groups.
module Mark : sig ... endMarks
High Level Operations
val all : ?pos:int -> ?len:int -> re -> string -> Group.t listRepeatedly calls
execon the given string, starting at given position and length.
val all_gen : ?pos:int -> ?len:int -> re -> string -> Group.t genSame as
allbut returns a generator
val all_seq : ?pos:int -> ?len:int -> re -> string -> Group.t Stdlib.Seq.tSame as
allbut returns an iterator- since
- NEXT_RELEASE
val matches : ?pos:int -> ?len:int -> re -> string -> string listSame 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 genSame as
matches, but returns a generator.
val matches_seq : ?pos:int -> ?len:int -> re -> string -> string Stdlib.Seq.tSame as
matches, but returns an iterator- since
- NEXT_RELEASE
val split : ?pos:int -> ?len:int -> re -> string -> string listsplit re ssplitssinto 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 genval split_seq : ?pos:int -> ?len:int -> re -> string -> string Stdlib.Seq.t- since
- NEXT_RELEASE
type split_token=[|`Text of stringText between delimiters
|`Delim of Group.tDelimiter
]
val split_full : ?pos:int -> ?len:int -> re -> string -> split_token listval split_full_gen : ?pos:int -> ?len:int -> re -> string -> split_token genval 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 -> stringreplace ~all re ~f siterates ons, and replaces every occurrence ofrewithf substringwheresubstringis the current match. Ifall = false, then only the first occurrence ofreis replaced.
val replace_string : ?pos:int -> ?len:int -> ?all:bool -> re -> by:string -> string -> stringreplace_string ~all re ~by siterates ons, and replaces every occurrence ofrewithby. Ifall = false, then only the first occurrence ofreis replaced.
String expressions (literal match)
Basic operations on regular expressions
val empty : tMatch nothing
val epsilon : tEmpty word
String, line, word
val bol : tBeginning of line
val eol : tEnd of line
val bow : tBeginning of word
val eow : tEnd of word
val bos : tBeginning of string
val eos : tEnd of string
val leol : tLast end of line or end of string
val start : tInitial position
val stop : tFinal position
val not_boundary : tNot at a word boundary
Match semantics
Repeated match modifiers
Groups (or submatches)
Character sets
val set : string -> tAny character of the string
val rg : char -> char -> tCharacter ranges
Predefined character sets
val any : tAny character
val notnl : tAny character but a newline
Case modifiers
Internal debugging
val pp : Stdlib.Format.formatter -> t -> unitval pp_re : Stdlib.Format.formatter -> re -> unitval print_re : Stdlib.Format.formatter -> re -> unitAlias for
pp_re. Deprecated
Experimental functions
.
val witness : t -> stringwitness rgenerates a stringssuch thatexecp (compile r) sis true
Deprecated functions
val get_ofs : Group.t -> int -> int * intSame as
Group.offset. Deprecated
val get_all_ofs : Group.t -> (int * int) arraySame as
Group.all_offset. Deprecated
val test : Group.t -> int -> boolSame as
Group.test. Deprecated
val mark_set : Group.t -> Mark.Set.tSame as
Mark.all. Deprecated