From 6adf38a26238eb28c6f7c751d727004574cab560 Mon Sep 17 00:00:00 2001 From: "Ryan M. Moore" Date: Mon, 19 Dec 2022 18:55:58 -0500 Subject: [PATCH] Add examples for Re.split function Adds a few examples of using zero-length patterns as inputs to Re.split. Examples are taken from the test suite. Related to #119 and #120. --- lib/core.mli | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/core.mli b/lib/core.mli index 63e4e948..c8ac96f3 100644 --- a/lib/core.mli +++ b/lib/core.mli @@ -303,7 +303,23 @@ val matches_seq : ?pos:int -> ?len:int -> re -> string -> string Seq.t # Re.split ~pos:3 regex "1,2,3,4. Commas go brrr.";; - : string list = ["3"; "4. Commas go brrr."] - ]} *) + ]} + + Be careful when using [split] with zero-length patterns like [eol], [bow], + and [eow]. + + {[ + # Re.split (Re.compile Re.eol) "a\nb";; + - : string list = ["a"; "\nb"] + + # Re.split (Re.compile Re.bow) "a b";; + - : string list = ["a "; "b"] + + # Re.split (Re.compile Re.eow) "a b";; + - : string list = ["a"; " b"] + ]} + + Note the position of the [\n] and space characters in the output. *) val split : ?pos:int -> ?len:int -> re -> string -> string list (** [split_delim re s] splits [s] into chunks separated by [re]. It