Skip to content

Commit

Permalink
Add examples for Re.split function
Browse files Browse the repository at this point in the history
Adds a few examples of using zero-length patterns as inputs to Re.split.  Examples are taken from the test suite.  Related to ocaml#119 and ocaml#120.
  • Loading branch information
mooreryan committed Jul 13, 2024
1 parent 9824792 commit 6adf38a
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/core.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6adf38a

Please sign in to comment.