-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Description
Both String.split
and Regex.split
(which the former relies on) have the following behavior when provided an empty pattern:
iex> String.split("abc", %r//)
["a", "b", "c", ""]
iex> Regex.split(%r//, "abc")
["a", "b", "c", ""]
While I understand we can provide the :trim
option and that this behavior matches Erlang's re module, namely:
[This] leaves an empty rest which is also returned. This behaviour differs from the default behaviour of the split function in Perl, where empty strings at the end are by default removed.
I thought it might make sense to discuss whether Elixir's more friendly (dare I say "modern") approach might provide an opening to change this to the more conventional behavior that I think most would expect. (I still don't understand why Erlang doesn't also return an empty value at the beginning of the result list.)
If the decision is made not to change this behavior, perhaps this behavior should be clearly stated in the Elixir docs, with doctest-able examples included.
Thoughts?