[Haskell-cafe] How to split this string.

emacsray at gmail.com emacsray at gmail.com
Mon Jan 2 12:19:55 CET 2012


On Mon, Jan 02, 2012 at 12:44:23PM +0300, max wrote:
> I want to write a function whose behavior is as follows:
>
> foo "string1\nstring2\r\nstring3\nstring4" = ["string1",
> "string2\r\nstring3", "string4"]
>
> Note the sequence "\r\n", which is ignored. How can I do this?
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

A short yet requiring regex solution:

  > import Text.Regex.PCRE
  > match (makeRegex "(?:[^\r\n]+|\r\n)+" :: Regex) "b\nc\r\n\n\r\n\nd" :: [[String]]



More information about the Haskell-Cafe mailing list