'Elm function to create a list of words, spaces and punctuation from a string sentence

I'm trying to create a sentence where each word, space, and punctuation character is in it's own HTML span. It would be for a language learning app so each span can be linked to the dictionary entry for that word. So I want something like String.split but with a regex as the delimiter, and to keep the delimiters as list items.

Basically exactly the same as this guy: Split a string into an array of words, punctuation and spaces in JavaScript, but in Elm.

I want to go from:

"Hello there. These are two sentences." : String

and get to:

["Hello", " ", "there", ".", " ", "These", " ", "are", " ", "two", " ", "sentences", "."] : List String

I'm pretty bamboozled so far.

Regards Chris



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source