Skip to content

String.split does not fully remove repeated patterns #1636

@vanstee

Description

@vanstee

When splitting with a pattern that is repeated, empty strings are left in the resulting list:

iex(1)> String.split("foo!bar!!!", %r/!/)
["foo", "bar", "", "", ""]               

I would expect the result to simply be:

["foo", "bar"]

String.split/1 seems to remove repeated whitespace, which makes it seem inconsistent:

iex(1)> String.split("foo bar   ")
["foo", "bar"]

This does start diverging from the semantics of :binary.split. Although we should probably at least support the :trim option, but that would still leave empty strings if the pattern is repeated at the beginning of the string.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions