Skip to content

Commit

Permalink
Clarify zero-length pattern split behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mooreryan committed Feb 4, 2024
1 parent 528a3fe commit ac26ae9
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/core.mli
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,12 @@ val split : ?pos:int -> ?len:int -> re -> string -> string list
- : string list = ["3"; "4. Commas go brrr."]
]}
{6 Zero-length patterns:}
Be careful when using [split] with zero-length patterns like [eol], [bow],
and [eow].
and [eow]. Because they don't have any width, they will still be present in
the result. (Note the position of the [\n] and space characters in the
output.)
{[
# Re.split (Re.compile Re.eol) "a\nb";;
Expand All @@ -314,7 +318,16 @@ val split : ?pos:int -> ?len:int -> re -> string -> string list
- : string list = ["a"; " b"]
]}
Note the position of the [\n] and space characters in the output.
Compare this to the behavior of splitting on the char itself. (Note that
the delimiters are not present in the output.)
{[
# Re.split (Re.compile (Re.char '\n')) "a\nb";;
- : string list = ["a"; "b"]
# Re.split (Re.compile (Re.char ' ')) "a b";;
- : string list = ["a"; "b"]
]}
*)

val split_gen : ?pos:int -> ?len:int -> re -> string -> string gen
Expand Down

0 comments on commit ac26ae9

Please sign in to comment.